HttpWebRequest DefaultNetworkCredentials give error 401

I'm trying to request a url that requires windows authentication using HttpWebRequest , I used

request.Credential = New NetworkCredential("username", "password"); 

everything worked until I decided not to write down the username and password, and switch to

 request.Credential = CredentialCache.DefaultNetworkCredentials; 

then I got 401 unauthenticated error. I checked my user with

 WindowsIdentity.GetCurrent(); 

It returns my username correctly, but

 CredentialCache.DefaultNetworkCredentials; 

return me an empty string for the username, domain ... almost all empty string. Too bad that HttpWebRequest.Credential expects ICredential means that I cannot set WindowsIdentity.GetCurrent () for it.

Anyway, can I pass my current login user to HttpWebRequest.Credential ??

Is CredentialCache.DefaultNetworkCredentials; in the right way? or are they just missing some settings?

I read some artistic, like this http://msdn.microsoft.com/en-us/library/ms998351.aspx .

Is this understanding too long and too complicated for me, or it does not work. I am new to this, hope to get a direct answer here.

+4
source share
1 answer

If you use basic authentication, this will not work. See This Question: HttpWebRequest with basic authentication fails with 401 erorr error for DefaultNetworkCredentials

And this Microsoft article says that DefaultCredentials only apply to NTLM, Kerberos-based reconciliation and validation. http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials.aspx

For information purposes, this article explains short authentication methods: http://msdn.microsoft.com/en-us/library/ms789031.aspx

+1
source

Source: https://habr.com/ru/post/1494235/


All Articles