Skip to content

Commit 86275f8

Browse files
committed
Document "url" parameter to HTTPConnection.request() (#102327)
1 parent f513d5c commit 86275f8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Doc/library/http.client.rst

+17-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ HTTPConnection Objects
264264
encode_chunked=False)
265265

266266
This will send a request to the server using the HTTP request
267-
method *method* and the selector *url*.
267+
method *method* and the request URI *url*.
268268

269269
If *body* is specified, the specified data is sent after the headers are
270270
finished. It may be a :class:`str`, a :term:`bytes-like object`, an
@@ -293,6 +293,22 @@ HTTPConnection Objects
293293
Transfer-Encoding header will automatically be set instead of
294294
Content-Length.
295295

296+
.. note::
297+
When using most HTTP methods (like ``GET`` or ``POST``)
298+
the provided ``url`` must be an absolute path and
299+
a ``Host`` header must be provided to conform with
300+
:rfc:`2616#section-5.1.2`.
301+
302+
For example, to perform a ``GET`` request to ``https://xkcd.com/353/``::
303+
304+
>>> import http.client
305+
>>> host = "xkcd.com"
306+
>>> conn = http.client.HTTPSConnection(host)
307+
>>> conn.request("GET", "/353/", headers={"Host": host})
308+
>>> response = conn.getresponse()
309+
>>> print(response.status, response.reason)
310+
200 OK
311+
296312
The *encode_chunked* argument is only relevant if Transfer-Encoding is
297313
specified in *headers*. If *encode_chunked* is ``False``, the
298314
HTTPConnection object assumes that all encoding is handled by the

0 commit comments

Comments
 (0)