I need to create a POST method in WebApi so I can send data from application to WebApi method. I\'m not able to get header value.
Here I have added header values in
For WEB API 2.0:
I had to use Request.Content.Headers instead of Request.Headers
and then i declared an extestion as below
///
/// Returns an individual HTTP Header value
///
///
///
///
public static string GetHeader(this HttpContentHeaders headers, string key, string defaultValue)
{
IEnumerable keys = null;
if (!headers.TryGetValues(key, out keys))
return defaultValue;
return keys.First();
}
And then i invoked it by this way.
var headerValue = Request.Content.Headers.GetHeader("custom-header-key", "default-value");
I hope it might be helpful