我目前正在编写一个HTTP客户端,在返回HTTP响应的URL上执行HTTP POST。
I am currently writing a HTTP client to do a HTTP POST on a URL that returns a HTTP response.
但是,对于错误消息代码400和500,它发回非分块的HTTP响应,对于成功消息201,它发送分块响应。
However, for error messages code 400 and 500, it sends back non chunked HTTP response, and for success messages, 201, it sends a chunked response.
在请求中,我正在设置内容长度,所以我不确定为什么它仍然向我们发送分块传输编码。我可以在请求中设置任何其他标头,这将告诉HTTP服务器不发送分块编码吗?
In the request, I am setting the content-length, so I am not sure why it is still sending us the chunked transfer encoding. Is there any other header I can set in the request, that will tell the HTTP server not to send chunked encoding?
headerList.append("POST /v2/charges HTTP/1.1") headerList.append("Content-Type: application/json") headerList.append("host: xxxxxxxxx") headerList.append("request-id: ABCD001123") headerList.append("Content-length: %d" %len(Msg)) hostReqHeader = "\r\n".join(headerList) reqData = hostReqHeader + '\r\n\r\n' + qbPosMsg我使用套接字发送这些HTTP消息,而不是使用httplib或请求库。
I am using sockets to send these HTTP messages, and not using httplib or requests library.
推荐答案Chunked是HTTP / 1.1的必需功能。如果您不需要任何其他1.1特定功能,请在您的请求中指定HTTP / 1.0:
Chunked is a required feature of HTTP/1.1. If you do not require any other 1.1-specific features, specify HTTP/1.0 in your request:
headerList.append("POST /v2/charges HTTP/1.0")更多推荐
如何告诉HTTP服务器不发送分块编码
发布评论