The server committed a protocol violation. Section = ResponseStatusLine when using tor proxy

I am trying to send httpwebrequest using tor proxy with my asp.net application and I get this error message when calling the webresponse.GetResponse () method:

The server committed a protocol violation. Section = ResponseStatusLine

I tried to find a solution on the Internet, and I found 3 main solutions to this error:

  • Add to Web.config.

    <system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true"/> </settings> </system.net>` 
  • Add the string webRequest.ProtocolVersion = HttpVersion.Version10; .

  • Add the line request.ServicePoint.Expect100Continue = false; into the code.

Each of these solutions did not change anything in the error message.

Here's the request 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 someone help me find a solution for this?

+8
c # proxy tor
source share
2 answers

You can get more detailed information about the exception you get, which is actually a WebException by looking at the Response property of the exception and then checking the StatusDescription and StatusCode . This will help you get more detailed information about the error and hopefully point you in the right direction.

Something like that:

  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); } } 

Also, see the WebException.Status example on MSDN for more information.

+3
source share

I had the same problem. The httpwebrequest getresponse method always returns the vialotion error protocol, and I decided to solve this path;

First of all, I use the xml com object instead of xdocument or xmldocument.

This com object has several versions of Microsft XML, v3.0-v5.0-v6.0. I used v6.0.

 MSXML2.DOMDocument60Class doc = new MSXML2.DOMDocument60Class(); doc.setProperty("ServerHTTPRequest",true); doc.setProperty("ProhibitDTD", false); doc.async = false; doc.load(extURL); if (doc.parseError.errorCode != 0) { // error } else { // do stuff } 
0
source share

All Articles