I have a simple question. I set a custom header like this:
var client = new HttpClient();
string urlWebApi = "urlOfMyApi";
client.BaseAddress = new Uri(urlWebApi);
client.DefaultRequestHeaders.Accept.Clear();
string token = "valueOfToken";
client.DefaultRequestHeaders.Add("Token", token);
How get the value of header "Token" in my Api?
In your API Controller, you should be able to access the HttpRequest which has a "Headers" property which is a collection of Key/Value pairs, so you can get it like this:
public HttpResponseMessage SomeControllerAction()
{
return Request.Headers["Token"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With