title: POST request with sockets
body: <p>I have to send post-request using pure sockets in c++. I can't understand where to send the body  of the request:</p>
  
  <pre><code>int *binary = new int[bufferLength];
  ...
  
  std::stringstream out(data);
  out &lt;&lt; "POST /push1_pub?id=game HTTP/1.1\n";
  out &lt;&lt; "Host: http://0.0.0.0:80\n";
  out &lt;&lt; "Content-Length: ";
  out &lt;&lt; bufferLength*sizeof(int);
  out &lt;&lt; "\r\n\r\n";
  out &lt;&lt; binary;
  
  if (socket.send(data.c_str(), data.size()) == -1)
  {
      std::cout &lt;&lt; "Failed to send headers\n";
  }
  else
  {
      // Send request body
      socket.send(reinterpret_cast&lt;char*&gt;(binary), bufferLength*sizeof(int));
      // Get the answer of server
      char buf[1024];
      std::cout &lt;&lt; socket.recv(buf, 1024) &lt;&lt; std::endl;
      std::cout &lt;&lt; buf &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>But in <code>buf</code> after sending body I have:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;400 Bad Request&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;400 Bad Request&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>What could be wrong here?</p>
  
  <hr>
  
  <p><strong>upd</strong>:</p>
  
  <p>New headers I have written due to your comments:</p>
  
  <pre><code>std::string data;
  std::stringstream out(data);
  out &lt;&lt; "POST /push1_pub?id=game\r\n";
  out &lt;&lt; "Host: http://localhost\r\n";
  out &lt;&lt; "Content-Length: ";
  out &lt;&lt; bufferLength &lt;&lt; "\r\n";
  out &lt;&lt; "\r\n\r\n";
  out &lt;&lt; binary;
  </code></pre>
  
  <p>Still have same problem.</p>
  
  <hr>
  
  <p><strong>upd2</strong></p>
  
  <p>With this command: <code>curl -s -v -X POST 'http://0.0.0.0/push1_pub?id=game' -d 'Test'</code> Everything works fine and post request is generated and sent right.</p>