How to get header values in https calls in c#

Viewed 4304

I have created an API which gets a header value which it matches with the apikey from the web.config.

enter image description here

and the code to get the header value in the application is

  var authToken = Request.Headers.Where(t => t.Key == "apiKey").ToList();

It works perfectly when I work with HTTP but when I use HTTPS it doesn't get the header value.

enter image description here

As shown in the image authToken.count = 0 which means it is not getting the header value.

The request object is of type public HttpRequestMessage Request { get; set; }

Can someone please suggest me where I am making the mistake.

1 Answers

To retrieve data from your Header You can use this Request.Headers, you will find an example below

var apiKey = Request.Headers.GetValues("apiKey")

Resquest From Postman

Resquest From Postman

Retrieve your data from header

Retrieve your data from header

Related