如何告诉HTTP服务器不发送分块编码 [英] How to tell the HTTP server to not send chunked encoding

查看:111
本文介绍了如何告诉HTTP服务器不发送分块编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个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服务器不发送分块编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆