none
The famous HttpWebRequest "The server committed a protocol violation. Section=ResponseStatusLine" RRS feed

  • Question

  • I'm using the HttpWebRequest class to request a web service.

    the problem is that when I use the GetResponse method it throws an exception with the message (The server committed a protocol violation. Section=ResponseStatusLine )
    I don't know why!!!

    the server responded with a valid Http response, given that I used Http Debugging proxy (Fiddler 2.0) that showed the Http response perfectly.

    could anybody tell me why I'm getting this Exception???
    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Thursday, July 23, 2009 2:53 PM

All replies

  • No clue but if you setup .NET Framework Source Code debugging you can probably track down whats throwing it off
    Thursday, July 23, 2009 3:08 PM
  • Hello,

    Are you using unsafe header parsing? Example of configuration below.

        <system.net>
            <settings>
                <httpWebRequest useUnsafeHeaderParsing="true" />
            </settings>
        </system.net>
    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    Thursday, July 23, 2009 3:09 PM
  • I also have the same problem, when I use fiddler, I see that the header is corrupted...
    Did you manage to solve this problem? I am stuck...
    Friday, July 24, 2009 7:35 PM

  • No clue yet!!!
    hay I need a hint to the right direction.

    any microsoft guy or MVP!!!


    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Friday, July 24, 2009 8:42 PM
  • Both me and Vitaliy gave valid ideas of what you could try, given you haven't provided feedback on either of them can I assume you didn't try them yet?
    Friday, July 24, 2009 9:00 PM
  • Hi
    In my case, The http response simply does not return Headers...
    I have tried vitaly's solution , with no luch  (put in in the App.Config and also from code)

    About the trace, don't think it's needed as I know the missing headers is the problem.

    Any other option to ignore the header?? 
    Friday, July 24, 2009 9:04 PM
  • If you check with fiddler, did you get the Http header OK ? or does it say your header is "Buggy" ?
    The reason it's working when fiddler is running, is that it's a proxy, and it replaces the corrupted info with another data...

    When you close fiddler, you get the original response which is still not "Http Protocol" valid...


    Friday, July 24, 2009 9:06 PM
  • I used the useUnsafeHeaderParsing configuration before posting my problem and I know the response is valid that's because fiddler viewed it and by the way the response is chunked, could it be the problem?

    and thank you for your interest.
    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Friday, July 24, 2009 9:38 PM
  • another hint that is driving me crazy:

    I used WebClient with the same request and it get the response successfully but the problem with this class is the timeout period (I want to change it and it doesn't provide that or other important control on the process)

    so I don't know why the HttpWebRequest is giving this exception while another managed class doesn't.
    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Friday, July 24, 2009 10:05 PM
  • any help or ideas will be appreciated.

    This exception is driving me crazy because the response is HTTP valid (both fiddler (debugging tool) and WebClient class proved this).

    sample code
                        HttpWebRequest HttpRequestObj = (HttpWebRequest)HttpWebRequest.Create(url);
                        HttpRequestObj.Credentials = CredentialCache.DefaultCredentials;
                        HttpRequestObj.ContentType = "text/plain";
                        HttpRequestObj.Timeout = Timeout.Infinite;
                        HttpRequestObj.Method = "GET";
                        HttpRequestObj.Accept = "text/plain";
                        HttpWebResponse response = (HttpWebResponse)HttpRequestObj.GetResponse();
                        System.IO.Stream responseStream = response.GetResponseStream();
    


    I assume the problem resides in:
    - the response is chunked and the HttpWebRequest can't parse chunked responses.
    - this is a bug in the HttpWebRequest class.

    does anybody have an idea???

    thanks in advance.



    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Sunday, July 26, 2009 9:16 AM
  • The server is apache and fiddler response is

    HTTP/1.1 14 "ERROR - Invalid query string parameter"
    Server: Apache-Coyote/1.1
    Date: Sun, 26 Jul 2009 09:11:32 GMT
    -ERROR : 11 Number formatting failed 20090722-060102
    Transfer-Encoding: chunked

    32
    -ERROR 11 Number formatting failed 20090722-060102
    0

    We are volunteers, if the reply help you mark it as your answer. thanks!!
    Sunday, July 26, 2009 9:31 AM
  • Just put:

    [

    ConfigurationPropertyAttribute("useUnsafeHeaderParsing", DefaultValue = true)]In your class and  :

    useUnsafeHeaderParsing

    = true; in your method...
    Friday, January 4, 2013 2:52 PM
  • We were facing the same issue from a long time and then came across this post.
    http://www.webmonkeys.org.uk/2012/09/c-the-server-committed-a-protocol-violation-sectionresponsestatusline/#comment-60

    Keeping “request.KeepAlive = false;” while making request solved our problem.

    Wednesday, February 26, 2014 1:34 PM