0

I'm trying to make GET/Post request with Authorization (NTLM / BASIC). Code works fine for all GET requests, but gets 401 unauthorized for any POST request.

My code:

NetworkCredential credential = new NetworkCredential(user, password);
var myCache = new CredentialCache
{
    { uri, auth, credential } // auth = "BASIC" or "NTLM"
};

var handler = new HttpClientHandler
{
    AllowAutoRedirect = true,
    PreAuthenticate = true,
    Credentials = myCache
};
HttpClient httpClient = new HttpClient(handler);
...
StringContent content = new StringContent(bodyText);
httpClient.PostAsync(uri, content).Result; // returns 401
Wsl_F
  • 832
  • 1
  • 7
  • 16

1 Answers1

0

What is the code that is being run on the PUT request? The chances are that the username/password combination you are using does not actually have WRITE access to a resource and thus you are receiving an unauthorised error.

If you have access to the code that is receiving the PUT call, check what files/folders that it is trying to write to. If not, contact the people who own that service and ask them why it is failing.

netniV
  • 2,328
  • 1
  • 15
  • 24
  • I don't have access to code that receiving PUT request, but credentials is 100% correct and has access level that needed – Wsl_F Nov 29 '17 at 12:47
  • Do you have access to the server? If it is IIS, you could use the Failed Request Tracing to see what the error is. If it is Apache, check the error log file. – netniV Nov 29 '17 at 12:53