[Python-checkins] cpython (3.2): #17307 - Example of HTTP PUT Request using http.client

senthil.kumaran python-checkins at python.org
Wed Mar 13 21:40:32 CET 2013


http://hg.python.org/cpython/rev/d4ab6556ff97
changeset:   82651:d4ab6556ff97
branch:      3.2
parent:      82638:df27ea4bdebd
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Wed Mar 13 13:38:33 2013 -0700
summary:
  #17307 - Example of HTTP PUT Request using http.client

files:
  Doc/library/http.client.rst |  16 ++++++++++++++++
  1 files changed, 16 insertions(+), 0 deletions(-)


diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst
--- a/Doc/library/http.client.rst
+++ b/Doc/library/http.client.rst
@@ -612,6 +612,22 @@
    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:
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list