服务器犯了违反协议。第=使用代理器时ResponseStatusLine [英] The server committed a protocol violation. Section=ResponseStatusLine when using a tor proxy
问题描述
我试图用器代理与我的asp.net应用程序发送HttpWebRequest和调用webresponse.GetResponse()方法时,我收到此错误信息:
I'm trying to send an httpwebrequest using a tor proxy with my asp.net application and I receive this error message when calling the webresponse.GetResponse() method:
服务器犯了违反协议。第= ResponseStatusLine
The server committed a protocol violation. Section=ResponseStatusLine
我试图寻找在网络上的解决方案,我发现这个错误3主要的解决方案:
I've tried searching for a solution on the web and I found 3 main solutions for this error:
-
添加到Web.config文件。
Add to Web.config.
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>`
添加一行: webRequest.ProtocolVersion = HttpVersion.Version10;
到code
列出解决方案中的每一个都不会改变任何事情有关的错误消息。
Each one of the listed solutions didn't change a thing about the error message.
下面是请求code:
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;
谁能帮我找到了一个解决方案?
Can anyone help me find a solution for this?
推荐答案
您可以了解你所得到的例外,这实际上是一个的引发WebException 通过寻找异常的响应
属性,然后检查状态说明
和状态code
属性。这将有助于你得到有关该错误的更多详细信息,希望你指出正确的方向。
You can get more details about the exception you are getting which is actually a WebException by looking at the Response
property of the exception and then checking the StatusDescription
and StatusCode
properties. That will help you get more details about the error and hopefully point you in the right direction.
事情是这样的:
catch(WebException e)
{
if(e.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
}
}
另外,看看 WebException.Status 例子在MSDN上获得更多的细节。
Also, take a look at WebException.Status example on MSDN to get more details
这篇关于服务器犯了违反协议。第=使用代理器时ResponseStatusLine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!