user1127081
user1127081

Reputation: 181

Webrequest returns 401 but same request using postman works

I have a c# client that is calling a webapi web service (iis 6). I am able to execute my web calls successfully from postman - No Authentication (Normal tab). The same call from the c# webclient fails.

Looking at the requests in fiddler I don't see a difference between the two.

Below is the request I am sending (postman and webclient) no headers are set.

https://store.isswerver.com/api/details/Users - Succeeds from postman client

Returns 401 using c# client

_client = new WebClient();
_client.Headers.Add("Content-Type", "application/json; charset=utf-8");
_client.Headers.Add("Accept", "application/json");
 byte[] data = _client.DownloadData(string.Format("{0}/Users", _apiUrl));

The client does work if I run the website on my local machine.

What is different in the way postman is submitting the request?

Upvotes: 0

Views: 6631

Answers (1)

Albireo
Albireo

Reputation: 11085

Check with a sniffer what Postman is actually sending on the wire and compare it with what you're sending for any kind of difference, both in the headers and the payload.

401 Unauthorized usually means you haven't supplied authentication credentials, however servers can return whichever status code they want for whichever reason (e.g. there's nothing preventing them to return a 401 status if they don't like the user agent).

Upvotes: 1

Related Questions