]> granicus.if.org Git - python/commitdiff
#17307 - Example of HTTP PUT Request using http.client
authorSenthil Kumaran <senthil@uthcode.com>
Wed, 13 Mar 2013 20:38:33 +0000 (13:38 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 13 Mar 2013 20:38:33 +0000 (13:38 -0700)
Doc/library/http.client.rst

index d439f246139879294090aecda73e3d306bdf11f1..408a3e7bb0fc873f8f0e5e85b1404dc122b1accf 100644 (file)
@@ -612,6 +612,22 @@ 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>'
    >>> 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::
+
+    >>> # 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: