title: HTTP headers for chunked encoding POST - Error 411
body: <p>I'm sending data to a server with an <a href="https://stackoverflow.com/questions/3677400/making-a-http-post-request-using-arduino">Arduino which requires constructing an HTML POST line-by-line</a>. I don't necessarily know the Content-Length a-priori, so I am using "chunked" encoding.   </p>
  
  <p>When I tried <a href="http://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example" rel="nofollow noreferrer">this example post from Wikipedia</a> with the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41" rel="nofollow noreferrer">"Transfer-Encoding" option as specified in rfc2616</a></p>
  
  <pre><code>client.println("POST /myurl HTTP/1.1");
  client.println("Host: 12.345.679.999"); // replaced with the test server's IP
  client.println("User-Agent: Arduino/1.0");
  client.println("Transfer-Encoding: chunked");
  client.println();  
  client.println("4");
  client.println("test");
  client.println("0");
  client.println();
  </code></pre>
  
  <p>or, with escape characters explicit:</p>
  
  <pre><code>client.print("4\r\ntest\r\n0\r\n\r\n");
  </code></pre>
  
  <p>I receive the error from my server: </p>
  
  <pre><code>HTTP/1.1 411 Length Required
  A request of the requested method POST requires a valid Content-length.
  Server: Apache/2.2.22 (Ubuntu)
  </code></pre>
  
  <p>However, "chunked" encoding shouldn't require a Content-Length header field, see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html" rel="nofollow noreferrer">4.4 - Message Length in rfc2616</a></p>
  
  <p>Am I missing a field? Why doesn't this call work?</p>
  
  <p>For the record, the non-Chunked-Encoding works:</p>
  
  <pre><code>if(client.connect(server, 80)){
      String PostData = "test";
      Serial.println("POST /myurl HTTP/1.1");
      client.println("Host: 12.345.679.999"); // replaced with the test server's IP
      Serial.println("User-Agent: Arduino/1.0");
      Serial.print("Content-Length: ");
      Serial.println(PostData.length());
      Serial.println();
      Serial.println(PostData);
  }
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <p>From the apache2 error.log: "chunked Transfer-Encoding forbidden"</p>