mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
#17307 - merge from 3.3
This commit is contained in:
commit
1428e1335f
2 changed files with 27 additions and 0 deletions
|
@ -633,6 +633,24 @@ Here is an example session that shows how to ``POST`` requests::
|
||||||
b'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
|
b'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
|
||||||
>>> conn.close()
|
>>> conn.close()
|
||||||
|
|
||||||
|
Client side ``HTTP PUT`` requests are very similar to ``POST`` requests. The
|
||||||
|
difference lies only the server side where HTTP server will allow resources to
|
||||||
|
be created via ``PUT`` request. It should be noted that custom HTTP methods
|
||||||
|
+are also handled in :class:`urllib.request.Request` by sending the appropriate
|
||||||
|
+method attribute.Here is an example session that shows how to do ``PUT``
|
||||||
|
request using http.client::
|
||||||
|
|
||||||
|
>>> # This creates an HTTP message
|
||||||
|
>>> # with the content of BODY as the enclosed representation
|
||||||
|
>>> # for the resource http://localhost:8080/foobar
|
||||||
|
...
|
||||||
|
>>> import http.client
|
||||||
|
>>> BODY = "***filecontents***"
|
||||||
|
>>> conn = http.client.HTTPConnection("localhost", 8080)
|
||||||
|
>>> conn.request("PUT", "/file", BODY)
|
||||||
|
>>> response = conn.getresponse()
|
||||||
|
>>> print(resp.status, response.reason)
|
||||||
|
200, OK
|
||||||
|
|
||||||
.. _httpmessage-objects:
|
.. _httpmessage-objects:
|
||||||
|
|
||||||
|
|
|
@ -1141,6 +1141,15 @@ The code for the sample CGI used in the above example is::
|
||||||
data = sys.stdin.read()
|
data = sys.stdin.read()
|
||||||
print('Content-type: text-plain\n\nGot Data: "%s"' % data)
|
print('Content-type: text-plain\n\nGot Data: "%s"' % data)
|
||||||
|
|
||||||
|
Here is an example of doing a ``PUT`` request using :class:`Request`::
|
||||||
|
|
||||||
|
import urllib.request
|
||||||
|
DATA=b'some data'
|
||||||
|
req = urllib.request.Request(url='http://localhost:8080', data=DATA,method='PUT')
|
||||||
|
f = urllib.request.urlopen(req)
|
||||||
|
print(f.status)
|
||||||
|
print(f.reason)
|
||||||
|
|
||||||
Use of Basic HTTP Authentication::
|
Use of Basic HTTP Authentication::
|
||||||
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue