title: C#: HttpClient, The server committed a protocol violation. Section=ResponseStatusLine
body: <p>I'm using the <a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx" rel="nofollow noreferrer">HttpClient</a> class to communicate to a web service in my WPF application.</p>
  
  <p>When I make consecutive GET requests on the same connection, everything works fine.  However, when I make consecutive PUT/PATCH requests on the same connection, the first request executes accurately and I receive a response but the second request does not include the body in the request and I receive the infamous error of "The server committed a protocol violation. Section=ResponseStatusLine".</p>
  
  <p>My requests do complete successfully if I manually close the connection after every request by adding <b>Connection: close</b> to the header.  This "solution" is a bad pattern and performance will not scale appropriately.</p>
  
  <p>Below is a debranded version of a list of my TCP Stream Output from the requests being sent:</p>
  
  <p><b>Wireshark: Follow TCP Stream Output</b></p>
  
  <pre><code>GET /domain/api/tenant/current/object?objectName=Lizbot HTTP/1.1
  Accept: application/json
  
      HTTP/1.1 200 OK
      Content-Type: application/json; charset=utf-8
      Content-Length: 50
      {"Data":[{"Id":123,"ObjectName":"Lizbot","Date":null}],"Errors":[]}
  
  PATCH /domain/api/tenant/current/object/123 HTTP/1.1
  Accept: application/json
  Content-Type: application/json; charset=utf-8
  Content-Length: 50
  {"Id":123,"ObjectName":"Lizbot","Date":null}
  
      HTTP/1.1 204 No Content
      Content-Type: application/json; charset=utf-8
      {"Data":null,"Errors":[]}
  
  PATCH /domain/api/tenant/current/object/123/otherObject HTTP/1.1
  Accept: application/json
  Content-Type: application/json; charset=utf-8
  
      HTTP/1.1 400 Bad Request&lt;/b&gt;
      Content-Type: text/html; charset=us-ascii
      Connection: close
      Content-Length: 311
  </code></pre>
  
  <p>Notice that the second PATCH is missing the object it's supposed to patch with.  If I change the order of the PATCHing, the second PATCH is still missing its object.</p>
  
  <p>This error appears to be common with a few known solutions which I have tried.  They consist of <a href="https://stackoverflow.com/a/2482730/1403925">this solution</a> which involves setting the useUnsafeHeaderParsing property to <b>TRUE</b> and setting the Keep-Alive property to <B>FALSE</B> in the Web.Config.  I also tried the solution of setting these properties in this manner shown below:</p>
  
  <pre><code> ServicePointManager.DefaultConnectionLimit = 2;
   ServicePointManager.Expect100Continue = false;
  </code></pre>
  
  <p>None of these solutions worked.  It should be noted that when using the Http Debugging proxy tool, Fiddler, to capture these requests, I don't receive any errors.</p>
  
  <p>So what I am asking for is if anyone knows a good solution to alleviate this error so I can make multiple requests in a connection without losing the body of an update.  If more details are needed, I am happy to supply them.</p>