📄 module-httplib.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.4 httplib -- HTTP protocol client</title>
<META NAME="description" CONTENT="11.4 httplib -- HTTP protocol client">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-ftplib.html" tppabs="http://www.python.org/doc/current/lib/module-ftplib.html">
<LINK REL="previous" href="module-urllib.html" tppabs="http://www.python.org/doc/current/lib/module-urllib.html">
<LINK REL="up" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">
<LINK REL="next" HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="Urllib_Examples.html" tppabs="http://www.python.org/doc/current/lib/Urllib_Examples.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="Urllib_Examples.html" tppabs="http://www.python.org/doc/current/lib/Urllib_Examples.html">11.3.2 Examples</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html">11.4.1 HTTP Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0013400000000000000000">
11.4 <tt class="module">httplib</tt> --
HTTP protocol client</A>
</H1>
<P>
<P>
<P>
This module defines a class which implements the client side of the
HTTP protocol. It is normally not used directly -- the module
<tt class='module'><a href="module-urllib.html" tppabs="http://www.python.org/doc/current/lib/module-urllib.html">urllib</a></tt> uses it to handle URLs that
use HTTP.
<P>
The module defines one class, <tt class="class">HTTP</tt>:
<P>
<dl><dt><b><a name='l2h-2020'><tt class='class'>HTTP</tt></a></b> (<big>[</big><var>host</var><big>[</big><var>, port</var><big>]</big><big>]</big>)
<dd>
An <tt class="class">HTTP</tt> instance
represents one transaction with an HTTP server. It should be
instantiated passing it a host and optional port number. If no port
number is passed, the port is extracted from the host string if it has
the form <code><var>host</var>:<var>port</var></code>, else the default HTTP port (80)
is used. If no host is passed, no connection is made, and the
<tt class="method">connect()</tt> method should be used to connect to a server. For
example, the following calls all create instances that connect to the
server at the same host and port:
<P>
<dl><dd><pre class="verbatim">
>>> h1 = httplib.HTTP('www.cwi.nl')
>>> h2 = httplib.HTTP('www.cwi.nl:80')
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
</pre></dl>
<P>
Once an <tt class="class">HTTP</tt> instance has been connected to an HTTP server, it
should be used as follows:
<P>
<DL COMPACT>
<DT>1.</DT>
<DD>Make exactly one call to the <tt class="method">putrequest()</tt> method.
<P>
</DD>
<DT>2.</DT>
<DD>Make zero or more calls to the <tt class="method">putheader()</tt> method.
<P>
</DD>
<DT>3.</DT>
<DD>Call the <tt class="method">endheaders()</tt> method (this can be omitted if
step 4 makes no calls).
<P>
</DD>
<DT>4.</DT>
<DD>Optional calls to the <tt class="method">send()</tt> method.
<P>
</DD>
<DT>5.</DT>
<DD>Call the <tt class="method">getreply()</tt> method.
<P>
</DD>
<DT>6.</DT>
<DD>Call the <tt class="method">getfile()</tt> method and read the data off the
file object that it returns.
<P>
</DD>
</DL>
</dl>
<P>
<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
<UL>
<LI><A NAME="tex2html3944"
HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html">11.4.1 HTTP Objects</A>
<LI><A NAME="tex2html3945"
href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">11.4.2 Examples</A>
</UL>
<!--End of Table of Child-Links-->
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="Urllib_Examples.html" tppabs="http://www.python.org/doc/current/lib/Urllib_Examples.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="Urllib_Examples.html" tppabs="http://www.python.org/doc/current/lib/Urllib_Examples.html">11.3.2 Examples</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node252.html" tppabs="http://www.python.org/doc/current/lib/node252.html">11.4.1 HTTP Objects</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -