Reading headers in Webapi

Asked

Viewed 946 times

0

I have a code that posts to a url and adds some parameters to the request header

HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Cache-Control", "no-cache");
req.Headers.Add("X-ICM-API-Authorization", token);

How do code to read these parameters that are in the header in the Web API?

  • you make the request in a local or external URL? you can put the codes beyond this?

  • Hello Virgilio, what I need is to do the server-side encoding to respond to this request, and I need to read the X-ICM-API-Authorization that was sent in Headers

  • http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api or http://www.dotnetcurry.com/aspnet/1223/secure-aspnet-web-apiusing-tokens-owin-angularjs ?? would be one of those links? !!!

1 answer

1


If your controller inherits from ApiController, you can recover the headers of the requisition through the property Request, who in turn owns a property Headers.

In the specific case of authentication/authorization I suggest using a Message Handler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.