Python http.client请求和putrequest之间有什么区别?

2024-10-02 22:30:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现解释http.client for Python的文档似乎有点稀疏。我想在请求上使用它,因为请求对我们的项目不起作用

因此,知道我正在使用Python的http.client,我一次又一次地看到requestputrequest。这两种方法都是在HTTPConnection下定义的here

HTTPConnection.request: This will send a request to the server using the HTTP request method method and the selector url.

HTTPConnection.putrequest: This should be the first call after the connection to the server has been made. It sends a line to the server consisting of the method string, the url string, and the HTTP version (HTTP/1.1). To disable automatic sending of Host: or Accept-Encoding: headers (for example to accept additional content encodings), specify skip_host or skip_accept_encoding with non-False values.

另外,这两个的源代码都在this file中定义

根据我的猜测和阅读,与putrequest相比request似乎是一个更高级的API。对吗


Tags: andofthetoclienthttpurlfor
1条回答
网友
1楼 · 发布于 2024-10-02 22:30:57

答案:request()是多个函数的抽象版本,putrequest()就是其中之一。

虽然这在文档中有定义,但是很容易跳过回答这个问题的那一行

这一点在http.client文档的这一行中指出:

As an alternative to using the request() method described above, you can also send your request step by step, by using the four functions below.

相关问题 更多 >