locked
How to set useUnsafeHeaderParsing of HttpClient

    Question

  • I use httpClient to get data from a server, but it the response will throw an exception:

    The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF

    In asp.net we can set webrequest's useUnsafeHeaderParsing to resolve the problem

    <system.net>
      <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />  
      </settings>
    </system.net>
    but in metro app, how should I do?
    Tuesday, July 17, 2012 1:42 AM

Answers

  • You will have to ensure that the server is not creating a protocol violation.  You may have to contact the owner of the server to have them correct the problem.  There is no way to bypass this error in Metro style apps.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, July 18, 2012 3:52 PM
    Moderator

All replies

  • I have try set HttpClient's http version as  http1.0, sometime it works, but not all the time.
    Tuesday, July 17, 2012 9:34 AM
  • You will have to ensure that the server is not creating a protocol violation.  You may have to contact the owner of the server to have them correct the problem.  There is no way to bypass this error in Metro style apps.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, July 18, 2012 3:52 PM
    Moderator
  • Unfortunately there are web cameras and other embedded servers that cannot easily be changed (like millions of Panasonic web cameras).  Is there any chance of getting this option reconsidered?

    Mark Miller

    Thursday, December 20, 2012 4:58 AM
  • Yes, you can file a connect bug here: http://connect.microsoft.com/VisualStudio

    The only other options are to find third party .NET HTTP library that allows for unsafe headers or use the Socket classes to implement your own HTTP Protocol handler.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, December 20, 2012 4:22 PM
    Moderator
  • I had to deal with this in a Windows Phone 8.1 (Silverlight) application and ended up using StreamSocket which should also be available for Windows Store. As a matter of fact, there is probably an even simpler solution available for RT apps using MessageWebSocket.

    I outlined the basic idea for a solution at http://www.jedidja.ca/dealing-with-a-protocol-violation-on-wp-8-1/

    Monday, August 11, 2014 11:05 PM