可以在WebClient类上使用吗?
E.g。类似的东西:
MyWebClient.AllowAutoRedirect = false; (of HttpWebRequest)
答案 0 :(得分:22)
您可以编写自定义Web客户端并启用此功能:
public class WebClientEx : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var request = (HttpWebRequest)base.GetWebRequest(address);
request.AllowAutoRedirect = false;
return request;
}
}
然后:
using (var client = new WebClientEx())
{
Console.WriteLine(client.DownloadString("http://google.com"));
}