title: C++ Http POST 400 bad request
body: <p>The following code was able to perform a post request on my (unchanged) server until recently. Since a couple of weeks I got a 400 bad request response. What could be the problem? A POST send with command line curl works fine.</p>
  
  <pre><code>std::ostringstream oss;
  oss &lt;&lt; "mydata";
  
  int size = oss.tellp();
  std::string test = oss.str();
  
  boost::asio::ip::tcp::iostream stream;
  stream.connect("myserver.nl", "http");
  stream &lt;&lt; "POST /dir/newdata.php  HTTP/1.1\r\n";
  stream &lt;&lt; "Host: myserver.nl\r\n";
  stream &lt;&lt; "Accept: */*\r\n";
  stream &lt;&lt; "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
  stream &lt;&lt; "Content-Length: " &lt;&lt; size &lt;&lt; "\r\n";
  stream &lt;&lt; "Connection: close\r\n\r\n";
  
  stream &lt;&lt; oss.str();
  stream.flush();
  std::cout  &lt;&lt; stream.rdbuf();
  </code></pre>
  
  <p>It now results in the following error:</p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Date: Tue, 20 Feb 2018 09:22:15 GMT
  Server: Apache/2.4.29 (Unix)
  Content-Length: 226
  Connection: close
  Content-Type: text/html; charset=iso-8859-1
  
  &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;400 Bad Request&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Bad Request&lt;/h1&gt;
  &lt;p&gt;Your browser sent a request that this server could not understand.&lt;br/&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p></p>