如何告诉HTTP服务器不发送分块编码

编程入门 行业动态 更新时间:2024-10-14 08:25:56
本文介绍了如何告诉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服务器不发送分块编码

本文发布于:2023-10-11 14:19:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481949.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!