我正在向具有
Arduino which requires constructing an HTML POST line-by-line的服务器发送数据.我不一定知道“内容长度”,所以我使用“chunked”编码.
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();
或者,转义字符显式:
client.print("4\r\ntest\r\n0\r\n\r\n");
我从我的服务器收到错误:
HTTP/1.1 411 Length Required
A request of the requested method POST requires a valid Content-length.
Server: Apache/2.2.22 (Ubuntu)
但是,“chunked”编码不应该需要Content-Length头域,参见4.4 – Message Length in rfc2616
我错过了一个领域吗?为什么这个电话不工作?
对于记录,非分块编码的作品:
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);
}
UPDATE
从apache2 error.log:“chunked Transfer-Encoding禁止”