Add X-Auth-Token - C # HttpClient

I am trying to add “X-Auth-Token” as a header on my HttpClient, and I get 403 error when I make a request, which makes sense because I don't think my X-Auth-Token is attached as a header.

How can I specify "X-Auth-Token" in my header?

Here is the relevant code:

using (var c = new HttpClient())
{
    c.BaseAddress = new Uri(url); 
    c.DefaultRequestHeaders.Accept.Clear(); 
    c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
    c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);
+4
source share
1 answer

You can use the method Addto add a title.

c.DefaultRequestHeaders.Add("x-auth-token", token);

The AuthenticationHeaderValue constructor accepts scheme. I'm not sure what it is, but probably will be on these

http://msdn.microsoft.com/en-us/library/ms789031(v=vs.110).aspx

+3
source

Source: https://habr.com/ru/post/1568038/


All Articles