httplib doc (was: CVS: python/dist/src/Doc/lib libhttplib.tex,1.19,1.20)

June 28, 2000
10:16 p.m.
Please mark me for a TODO to update the httplib doc. For example, the code below is more effectively written as: h = httplib.HTTPConnection('www.musi-cal.com') h.request('POST', '/cgi-bin/query', paramstring, {'Accept': 'text/plain'}) response = h.getresponse() print response.status # should be 200 data = response.read() # get the raw HTML Note that 'Accept' is usually not a required header and can be omitted in most scenarios. I left it in the example simply to show how to fully map between the old/new APIs. [ Content-Length and Host are sent automatically by HTTPConnection. ] Cheers, -g On Wed, Jun 28, 2000 at 02:51:46PM -0700, Fred L. Drake wrote: > Update of /cvsroot/python/python/dist/src/Doc/lib > In directory slayer.i.sourceforge.net:/tmp/cvs-serv5474/lib > > Modified Files: > libhttplib.tex > Log Message: > > Skip Montanaro <skip@mojam.com>: > Added an example of using an HTTP POST request. > > > Index: libhttplib.tex > =================================================================== > RCS file: /cvsroot/python/python/dist/src/Doc/lib/libhttplib.tex,v > retrieving revision 1.19 > retrieving revision 1.20 > diff -C2 -r1.19 -r1.20 > *** libhttplib.tex 1999/04/22 16:47:27 1.19 > --- libhttplib.tex 2000/06/28 21:51:43 1.20 > *************** > *** 115,119 **** > \nodename{HTTP Example} > > ! Here is an example session: > > \begin{verbatim} > --- 115,119 ---- > \nodename{HTTP Example} > > ! Here is an example session that uses the \samp{GET} method: > > \begin{verbatim} > *************** > *** 129,131 **** > --- 129,148 ---- > >>> 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} > > > _______________________________________________ > Python-checkins mailing list > Python-checkins@python.org > http://www.python.org/mailman/listinfo/python-checkins -- Greg Stein, http://www.lyra.org/
9122
Age (days ago)
9122
Last active (days ago)
0 comments
1 participants
participants (1)
-
Greg Stein