From: Senthil Kumaran Date: Wed, 13 Mar 2013 20:42:47 +0000 (-0700) Subject: #17307 - merge from 3.2 X-Git-Tag: v3.3.1rc1~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e66cc8172d604e07a6fcdc9cdeeb985b68c99583;p=python #17307 - merge from 3.2 --- e66cc8172d604e07a6fcdc9cdeeb985b68c99583 diff --cc Doc/library/http.client.rst index 5599dac187,408a3e7bb0..2d93aa47c3 --- a/Doc/library/http.client.rst +++ b/Doc/library/http.client.rst @@@ -633,6 -612,22 +633,24 @@@ Here is an example session that shows h b'Redirecting to http://bugs.python.org/issue12524' >>> 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. Here is an example session that shows how to do -``PUT`` request using http.client:: ++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: diff --cc Doc/library/urllib.request.rst index 505f738e3c,33244daf6e..2cf1304536 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@@ -1109,6 -1044,6 +1109,15 @@@ The code for the sample CGI used in th data = sys.stdin.read() 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:: import urllib.request