Making a web request to a web page which requires windows authentication

前端 未结 4 1842
轮回少年
轮回少年 2020-11-30 08:24

I am trying to make a request to a web page using WebRequest class in .net. The url that I am trying to read requires Windows Authentication due to which I get an unauthoris

相关标签:
4条回答
  • 2020-11-30 08:58

    You should use Credentials property to pass the windows credentials to the web service.

    If you wish to pass current windows user's credentials to the service then

    request.Credentials = CredentialCache.DefaultCredentials;
    

    should do the trick. Otherwise use NetworkCredential as follows:

    request.Credentials = new NetworkCredential(user, pwd, domain);
    
    0 讨论(0)
  • 2020-11-30 09:08

    I am trying to access a link A passing the windows credentials. Link A then redirects me to link B automatically but does not pass the windows credentials which I had supplied. Hence the error. I did request.AutoRedirect = false, and looped through every time I get location in the header i.e. I do my redirects manually each time passing the windows credentials.

    This worked for me :)

    0 讨论(0)
  • 2020-11-30 09:08

    Using VS2015, request.UseDefaultCredentials = true; works for me!

    0 讨论(0)
  • 2020-11-30 09:17

    For authenticating to WebService, use DefaultNetworkCredentials instead of DefaultCredentials:

    request.Credentials = CredentialCache.DefaultNetworkCredentials;
    
    0 讨论(0)
提交回复
热议问题