0

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?

3
  • HTTP 401 means Unauthorized so I would assume you are logged in when you do the request through the browser ? Commented Oct 2, 2014 at 14:08
  • 1
    What happens if you set _client.UseDefaultCredentials = true ? Commented Oct 2, 2014 at 14:30
  • _client.UseDefaultCredentials = true fixed it, I swear I had tried that Thanks! Commented Oct 2, 2014 at 15:02

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.