Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分块编码后的HTTP头-错误411_Http_Http Headers_Arduino_Http Post_Http Error - Fatal编程技术网

分块编码后的HTTP头-错误411

分块编码后的HTTP头-错误411,http,http-headers,arduino,http-post,http-error,Http,Http Headers,Arduino,Http Post,Http Error,我正在将数据发送到一个带有。我不一定事先知道内容长度,所以我使用“分块”编码 当我试着用 或者,使用显式转义字符: 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) 但是,“分

我正在将数据发送到一个带有。我不一定事先知道内容长度,所以我使用“分块”编码

当我试着用

或者,使用显式转义字符:

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)
但是,“分块”编码不需要内容长度头字段,请参阅

我错过了一个领域吗?为什么这个电话不起作用

对于记录,非分块编码工作:

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);
}
更新 从apache2 error.log中找到后:“禁止分块传输编码”

chunked Transfer-Encoding forbidden
在我的Apache2日志中,我得出结论,错误不在我所发的帖子中

我发现modwsgi(apache和django之间的中间层)默认情况下不启用分块传输编码

,我发现我在写作

WSGIChunkedRequest On

在我的apache
httpd.conf
文件中,允许分块请求(不再出现411错误)

不,您没有做错任何事情。它不起作用,因为编写服务器的人决定对包含实体体的请求要求
内容长度
头。如果您允许分块的实体体,那么解析请求消息就更复杂了,因为您必须在数据到达时解析数据,而如果您知道数据的长度,则可以读取该数量的八位字节。如果服务器具有禁用
内容长度
要求的选项设置,则您的请求应按预期工作。否则,您将陷入困境,因为“1.1兼容”服务器无法正确处理分块请求。相关:什么服务器软件正在侦听请求?谢谢。Apache/2.2.22(Ubuntu)上的AmazonEC2服务器。因此,我想我将深入研究Apache httpd.conf文件?我过去在向Apache服务器发送分块请求时没有遇到问题。您的请求行是否指定了
POST/someurl HTTP/1.1
?因为如果使用1.0,我希望使用411,因为HTTP/1.1引入了分块编码。否则,您应该可以通过谷歌搜索找出哪些设置可以说服apache接受分块请求。是的,我的请求行就是这样。啊,WSGI就是罪魁祸首。。。很高兴你能解决这个问题。通过上述方法,411不见了,但我现在得到了400。如果我禁用分块传输,它将按预期工作。
WSGIChunkedRequest On