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

一个人想着一个人 提交于 2019-11-27 08:34:05
VinayC

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

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

For authenticating to WebService, use DefaultNetworkCredentials instead of DefaultCredentials:

request.Credentials = CredentialCache.DefaultNetworkCredentials;

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!