webclient如何保持重定向时的基本授权 [英] webclient how to keep basic authorization when redirect

查看:952
本文介绍了webclient如何保持重定向时的基本授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用webclient调用Web服务,我通过用户名&密码作为webclient标题中的基本授权。请求被重定向到另一个URL,但基本的授权信息不包括在重定向的请求头中,所以我得到401未授权的错误。那么如何在重定向时保持请求标头中的授权信息?感谢
我注意到授权实际上是在cookies中进行

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

我使用C#,.NEt 4.0,VS2010

I am using C# , .NEt 4.0, VS2010

推荐答案

webclient删除您的客户验证标题,并有很好的理由!如果您重定向到谁知道在哪里?,您当然不想向他们发送您的身份验证信息!

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

但是很奇怪,你需要设置你的程序来手动处理重定向,然后使用webclient请求连接到正确的服务器。

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.

这篇关于webclient如何保持重定向时的基本授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆