ID EN
HTTP Client

request

Python 3.11

This will send a request to the server using the HTTP request method method and the request URI url. The provided url must be an absolute path to conform with RFC 2616 5.1.2 (unless connecting to an HTTP proxy server or using the OPTIONS or CONNECT methods).

Syntax

PYTHON
HTTPConnection.request(method, url, body=None, headers={}, *, encode_chunked=False)

Examples

Example 1
PYTHON
>>> import http.client
>>> host = "docs.python.org"
>>> conn = http.client.HTTPSConnection(host)
>>> conn.request("GET", "/3/", headers={"Host": host})
>>> response = conn.getresponse()
>>> print(response.status, response.reason)
200 OK

See Also

str bytes-like object file object bytes file object io.TextIOBase file str