http.client.HTTPConnection.request()

HTTPConnection.request(method, url, body=None, headers={})

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

If body is specified, the specified data is sent after the headers are finished. It may be a string, a bytes-like object, an open file object, or an iterable of bytes-like objects. If body is a string, it is encoded as ISO-8859-1, the default for HTTP. If it is a bytes-like object the bytes are sent as is. If it is a file object, the contents of the file is sent; this file object should support at least the read() method. If the file object has a mode attribute, the data returned by the read() method will be encoded as ISO-8859-1 unless the mode attribute contains the substring b, otherwise the data returned by read() is sent as is. If body is an iterable, the elements of the iterable are sent as is until the iterable is exhausted.

The headers argument should be a mapping of extra HTTP headers to send with the request.

If headers does not contain a Content-Length item, one is added automatically if possible. If body is None, the Content-Length header is set to 0 for methods that expect a body (PUT, POST, and PATCH). If body is a string or bytes object, the Content-Length header is set to its length. If body is a file object and it works to call fstat() on the result of its fileno() method, then the Content-Length header is set to the st_size reported by the fstat call. Otherwise no Content-Length header is added.

New in version 3.2: body can now be an iterable.

doc_python
2016-10-07 17:33:51
Comments
Leave a Comment

Please login to continue.