📄 node252.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.4.1 HTTP Objects</title>
<META NAME="description" CONTENT="11.4.1 HTTP Objects">
<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="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">
<LINK REL="previous" href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">
<LINK REL="up" href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">
<LINK REL="next" href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.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="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.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="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.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="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">11.4 httplib </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">11.4 httplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">11.4.2 Examples</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0013410000000000000000">
11.4.1 HTTP Objects</A>
</H2>
<P>
<tt class="class">HTTP</tt> instances have the following methods:
<P>
<dl><dt><b><a name='l2h-2023'><tt class='method'>set_debuglevel</tt></a></b> (<var>level</var>)
<dd>
Set the debugging level (the amount of debugging output printed).
The default debug level is <code>0</code>, meaning no debugging output is
printed.
</dl>
<P>
<dl><dt><b><a name='l2h-2024'><tt class='method'>connect</tt></a></b> (<var>host</var><big>[</big><var>, port</var><big>]</big>)
<dd>
Connect to the server given by <var>host</var> and <var>port</var>. See the
intro for the default port. This should be called directly only if
the instance was instantiated without passing a host.
</dl>
<P>
<dl><dt><b><a name='l2h-2025'><tt class='method'>send</tt></a></b> (<var>data</var>)
<dd>
Send data to the server. This should be used directly only after the
<tt class="method">endheaders()</tt> method has been called and before
<tt class="method">getreply()</tt> has been called.
</dl>
<P>
<dl><dt><b><a name='l2h-2026'><tt class='method'>putrequest</tt></a></b> (<var>request, selector</var>)
<dd>
This should be the first call after the connection to the server has
been made. It sends a line to the server consisting of the
<var>request</var> string, the <var>selector</var> string, and the HTTP version
(<code>HTTP/1.0</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-2027'><tt class='method'>putheader</tt></a></b> (<var>header, argument</var><big>[</big><var>, ...</var><big>]</big>)
<dd>
Send an <a class="rfc" name="rfcref-46979"
href="javascript:if(confirm('http://www.ietf.org/rfc/rfc0822.txt \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc0822.txt'" tppabs="http://www.ietf.org/rfc/rfc0822.txt">RFC 822 <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a> style header to the server. It sends a line to the
server consisting of the header, a colon and a space, and the first
argument. If more arguments are given, continuation lines are sent,
each consisting of a tab and an argument.
</dl>
<P>
<dl><dt><b><a name='l2h-2028'><tt class='method'>endheaders</tt></a></b> ()
<dd>
Send a blank line to the server, signalling the end of the headers.
</dl>
<P>
<dl><dt><b><a name='l2h-2029'><tt class='method'>getreply</tt></a></b> ()
<dd>
Complete the request by shutting down the sending end of the socket,
read the reply from the server, and return a triple
<code>(<var>replycode</var>, <var>message</var>, <var>headers</var>)</code>. Here,
<var>replycode</var> is the integer reply code from the request (e.g.,
<code>200</code> if the request was handled properly); <var>message</var> is the
message string corresponding to the reply code; and <var>headers</var> is
an instance of the class <tt class="class">mimetools.Message</tt> containing the
headers received from the server. See the description of the
<tt class='module'><a href="module-mimetools.html" tppabs="http://www.python.org/doc/current/lib/module-mimetools.html">mimetools</a></tt> module.
</dl>
<P>
<dl><dt><b><a name='l2h-2030'><tt class='method'>getfile</tt></a></b> ()
<dd>
Return a file object from which the data returned by the server can be
read, using the <tt class="method">read()</tt>, <tt class="method">readline()</tt> or
<tt class="method">readlines()</tt> methods.
</dl>
<P>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.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="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.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="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.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="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">11.4 httplib </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-httplib.html" tppabs="http://www.python.org/doc/current/lib/module-httplib.html">11.4 httplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="HTTP_Examples.html" tppabs="http://www.python.org/doc/current/lib/HTTP_Examples.html">11.4.2 Examples</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 + -