title: Sending HTTP POST requests using cpp-netlib
body: <p><strong>UPDATED</strong></p>
  
  <p>I'm using cpp-netlib (v0.11.0) to send HTTP requests.</p>
  
  <p>The following code sends an HTTP POST request with the given body.</p>
  
  <pre><code>client httpClient;
  
  try
  {
     uri::uri url;
     url &lt;&lt; uri::scheme("http")
         &lt;&lt; uri::host(m_hostname)
         &lt;&lt; uri::port(m_port)
         &lt;&lt; uri::path(m_path);
  
     // create a request instance and configure the headers
     client::request request(url);
     request &lt;&lt; header("Connection", "close");
     request &lt;&lt; header("Content-Type", "application/x-www-form-urlencoded");
  
     // send the request
     client::response response = httpClient.post(request, "foo=bar");
  }
  
  catch (std::exception&amp; ex)
  {
     ...
  }
  </code></pre>
  
  <p>However, the following code results in a bad request.</p>
  
  <pre><code>client httpClient;
  
  try
  {
     uri::uri url;
     url &lt;&lt; uri::scheme("http")
         &lt;&lt; uri::host(m_hostname)
         &lt;&lt; uri::port(m_port)
         &lt;&lt; uri::path(m_path)
         &lt;&lt; uri::query("foo", "bar");
  
    // create a request instance and configure the headers
     client::request request(url);
     request &lt;&lt; header("Connection", "close");
     request &lt;&lt; header("Content-Type", "application/x-www-form-urlencoded");
     request &lt;&lt; body("foo=bar");
  
     // send the request
     client::response response = httpClient.post(request);
  }
  
  catch (std::exception&amp; ex)
  {
     ...
  }
  </code></pre>
  
  <p>Please can someone explain what I'm doing wrong in the second example and which is the preferred option.</p>