我正在尝试通过我的 asp.net 应用程序使用 Tor 代理发送 httpwebrequest,并且在调用 webresponse.GetResponse() 方法时收到此错误消息:
服务器违反了协议。Section=ResponseStatusLine
我尝试在网上搜索解决方案,发现此错误的 3 个主要解决方案:
添加到 Web.config。
<system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true"/> </settings> </system.net>`
将行:添加
webRequest.ProtocolVersion = HttpVersion.Version10;
到代码中。- 将该行添加
request.ServicePoint.Expect100Continue = false;
到代码中。
列出的每个解决方案都没有改变错误消息的任何内容。
这是请求代码:
WebRequest.DefaultWebProxy = new WebRequest("127.0.0.1:9051");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.CookieContainer = new CookieContainer();
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.KeepAlive = false;
webRequest.Method = "GET";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19";
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
string html = streamReader.ReadToEnd();
webResponse.Close();
return html;
谁能帮我找到解决方案?