Saikat Bhattacharyya
Saikat Bhattacharyya

Reputation: 67

API fails to return response

I'm implementing a api made by gadventures.com in a ASP.NET MVC app project.

I have implemented below code to call the api

enter image description here

IsSuccessStatusCode returns false for the above code. It returns 401 unauthorized error. But I am able to get response in Postman.

enter image description here

Can you please help me to fix the issue?

Upvotes: 1

Views: 57

Answers (1)

Nkosi
Nkosi

Reputation: 246998

The header you are adding in postman is different to what you are doing in the code.

The code is setting .DefaultRequestHeaders.Authorization with a scheme and parameter, which would look like this when the request is sent.

Authorization X-Application-Key test_21be144dea7e9fa41b5817fe56d2697a2cfc1b20

while postman is adding a generic header, which would look like this when sent

X-Application-Key test_21be144dea7e9fa41b5817fe56d2697a2cfc1b20

Update the code to do the same thing.

client.DefaultRequestHeaders.TryAddWithoutValidation("X-Application-Key","test_21be144dea7e9fa41b5817fe56d2697a2cfc1b20");

Upvotes: 1

Related Questions