Fiddler无法捕获HttpWebRequest请求,且请求失败

用C# HttpWebRequest模拟请求时,如果打开Fiddler则请求超时且Fiddler无法捕获,而把Fiddler关闭就可以正常访问。

 

答案为:HttpWebRequest 请求头的Host头不要设置任何内容,注释即可访问,而非设置代理问题

 

 

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlToCrawl);
            req.Method = "GET";
            req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36";
            //req.Host = host;
            req.Referer = referer;
            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            req.Headers.Add("Accept-Encoding", "gzip,deflate,sdch;");
            //req.Proxy = WebProxy.GetDefaultProxy();
            //req.Proxy = new WebProxy("127.0.0.1:8888", true);

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            string htmlCharset = "GBK";
            Encoding htmlEncoding = Encoding.GetEncoding(htmlCharset);
            //StreamReader sr = new StreamReader(new GZipStream(resp.GetResponseStream(), CompressionMode.Decompress), htmlEncoding);
            StreamReader sr = new StreamReader(resp.GetResponseStream(), htmlEncoding);
            string respHtml = sr.ReadToEnd();

Fiddler无法捕获HttpWebRequest请求,且请求失败,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。