如何不遵守使用Web客户端类的头的位置? [英] How not following the location in headers using Web Client class?
本文介绍了如何不遵守使用Web客户端类的头的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是有可能在Web客户端类的? 像
MyWebClient.AllowAutoRedirect = FALSE; (中HttpWebRequest的)
解决方案
您可以编写一个自定义的Web客户端和启用的这种功能:
公共类WebClientEx:Web客户端
{
保护覆盖的WebRequest GetWebRequest(URI地址)
{
VAR请求=(HttpWebRequest的)base.GetWebRequest(地址);
request.AllowAutoRedirect = FALSE;
返回请求;
}
}
然后:
使用(VAR的客户=新WebClientEx())
{
Console.WriteLine(client.DownloadString(http://google.com));
}
is it possible on Web Client class? something like
MyWebClient.AllowAutoRedirect = false; (of HttpWebRequest)
解决方案
You could write a custom web client and enable this functionality:
public class WebClientEx : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var request = (HttpWebRequest)base.GetWebRequest(address);
request.AllowAutoRedirect = false;
return request;
}
}
and then:
using (var client = new WebClientEx())
{
Console.WriteLine(client.DownloadString("http://google.com"));
}
这篇关于如何不遵守使用Web客户端类的头的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文