webclient how to keep basic authorization when redirect

旧巷老猫 提交于 2019-12-24 15:19:33

问题


I use webclient to call a web service, I pass username & password as basic authorizaiton in webclient header. The request is redirected to another URL, but basic authorizaiton info is not included in the re-directed request header, so I get 401 not authorized error. So how to keep authorization info in request header when redirect? thanks I notice the authorization is actually carried in cookies

I am using C# , .NEt 4.0, VS2010


回答1:


webclient strips out your customer authentication headers, and for good reason! If you get redirected to who knows where?, you certainly don't want to be sending them your authentication information!

If you are getting redirected to somewhere in the same directory (I think?) then you can use

Request.PreAuthenticate = true

but odds are that you will need to set up your program to handle the redirect manually, and then use a webclient request to connect to the correct server.



来源:https://stackoverflow.com/questions/9846408/webclient-how-to-keep-basic-authorization-when-redirect

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