diff options
author | Fred Drake <fdrake@acm.org> | 2000-06-28 21:51:43 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-06-28 21:51:43 (GMT) |
commit | 4e716fa0ac08d241944840019676f3ce8b1a07c5 (patch) | |
tree | c99856b86df7d46eb7ab989ead69ee9566550044 /Doc/lib/libhttplib.tex | |
parent | fa4811699314bc0c35d74672aac68199d6890211 (diff) | |
download | cpython-4e716fa0ac08d241944840019676f3ce8b1a07c5.zip cpython-4e716fa0ac08d241944840019676f3ce8b1a07c5.tar.gz cpython-4e716fa0ac08d241944840019676f3ce8b1a07c5.tar.bz2 |
Skip Montanaro <skip@mojam.com>:
Added an example of using an HTTP POST request.
Diffstat (limited to 'Doc/lib/libhttplib.tex')
-rw-r--r-- | Doc/lib/libhttplib.tex | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Doc/lib/libhttplib.tex b/Doc/lib/libhttplib.tex index efdeac3..cb2dcc5 100644 --- a/Doc/lib/libhttplib.tex +++ b/Doc/lib/libhttplib.tex @@ -114,7 +114,7 @@ read, using the \method{read()}, \method{readline()} or \subsection{Example} \nodename{HTTP Example} -Here is an example session: +Here is an example session that uses the \samp{GET} method: \begin{verbatim} >>> import httplib @@ -129,3 +129,20 @@ Here is an example session: >>> data = f.read() # Get the raw HTML >>> f.close() \end{verbatim} + +Here is an example session that shows how to \samp{POST} requests: + +\begin{verbatim} +>>> import httplib, urllib +>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) +>>> h = httplib.HTTP("www.musi-cal.com:80") +>>> h.putrequest("POST", "/cgi-bin/query") +>>> h.putheader("Content-length", "%d" % len(params)) +>>> h.putheader('Accept', 'text/plain') +>>> h.putheader('Host', 'www.musi-cal.com') +>>> h.endheaders() +>>> h.send(paramstring) +>>> reply, msg, hdrs = h.getreply() +>>> print errcode # should be 200 +>>> data = h.getfile().read() # get the raw HTML +\end{verbatim} |