| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="httpresponse-objects.html" /> |
| 13 | <link rel="prev" href="module-httplib.html" /> |
| 14 | <link rel="parent" href="module-httplib.html" /> |
| 15 | <link rel="next" href="httpresponse-objects.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>11.6.1 HTTPConnection Objects </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="11.6 httplib " |
| 25 | href="module-httplib.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="11.6 httplib " |
| 28 | href="module-httplib.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="11.6.2 HTTPResponse Objects" |
| 31 | href="httpresponse-objects.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-httplib.html">11.6 httplib </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-httplib.html">11.6 httplib </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="httpresponse-objects.html">11.6.2 HTTPResponse Objects</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0013610000000000000000"></A><A NAME="httpconnection-objects"></A> |
| 56 | <BR> |
| 57 | 11.6.1 HTTPConnection Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | <tt class="class">HTTPConnection</tt> instances have the following methods: |
| 62 | |
| 63 | <P> |
| 64 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 65 | <td><nobr><b><tt id='l2h-3316' xml:id='l2h-3316' class="method">request</tt></b>(</nobr></td> |
| 66 | <td><var>method, url</var><big>[</big><var>, body</var><big>[</big><var>, headers</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 67 | <dd> |
| 68 | This will send a request to the server using the HTTP request method |
| 69 | <var>method</var> and the selector <var>url</var>. If the <var>body</var> argument is |
| 70 | present, it should be a string of data to send after the headers are finished. |
| 71 | The header Content-Length is automatically set to the correct value. |
| 72 | The <var>headers</var> argument should be a mapping of extra HTTP headers to send |
| 73 | with the request. |
| 74 | </dl> |
| 75 | |
| 76 | <P> |
| 77 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 78 | <td><nobr><b><tt id='l2h-3317' xml:id='l2h-3317' class="method">getresponse</tt></b>(</nobr></td> |
| 79 | <td><var></var>)</td></tr></table></dt> |
| 80 | <dd> |
| 81 | Should be called after a request is sent to get the response from the server. |
| 82 | Returns an <tt class="class">HTTPResponse</tt> instance. |
| 83 | <span class="note"><b class="label">Note:</b> |
| 84 | Note that you must have read the whole response before you can send a new |
| 85 | request to the server.</span> |
| 86 | </dl> |
| 87 | |
| 88 | <P> |
| 89 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 90 | <td><nobr><b><tt id='l2h-3318' xml:id='l2h-3318' class="method">set_debuglevel</tt></b>(</nobr></td> |
| 91 | <td><var>level</var>)</td></tr></table></dt> |
| 92 | <dd> |
| 93 | Set the debugging level (the amount of debugging output printed). |
| 94 | The default debug level is <code>0</code>, meaning no debugging output is |
| 95 | printed. |
| 96 | </dl> |
| 97 | |
| 98 | <P> |
| 99 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 100 | <td><nobr><b><tt id='l2h-3319' xml:id='l2h-3319' class="method">connect</tt></b>(</nobr></td> |
| 101 | <td><var></var>)</td></tr></table></dt> |
| 102 | <dd> |
| 103 | Connect to the server specified when the object was created. |
| 104 | </dl> |
| 105 | |
| 106 | <P> |
| 107 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 108 | <td><nobr><b><tt id='l2h-3320' xml:id='l2h-3320' class="method">close</tt></b>(</nobr></td> |
| 109 | <td><var></var>)</td></tr></table></dt> |
| 110 | <dd> |
| 111 | Close the connection to the server. |
| 112 | </dl> |
| 113 | |
| 114 | <P> |
| 115 | As an alternative to using the <tt class="method">request()</tt> method described above, |
| 116 | you can also send your request step by step, by using the four functions |
| 117 | below. |
| 118 | |
| 119 | <P> |
| 120 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 121 | <td><nobr><b><tt id='l2h-3321' xml:id='l2h-3321' class="method">putrequest</tt></b>(</nobr></td> |
| 122 | <td><var>request, selector</var><big>[</big><var>, |
| 123 | skip_host</var><big>[</big><var>, skip_accept_encoding</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 124 | <dd> |
| 125 | This should be the first call after the connection to the server has |
| 126 | been made. It sends a line to the server consisting of the |
| 127 | <var>request</var> string, the <var>selector</var> string, and the HTTP version |
| 128 | (<code>HTTP/1.1</code>). To disable automatic sending of <code>Host:</code> or |
| 129 | <code>Accept-Encoding:</code> headers (for example to accept additional |
| 130 | content encodings), specify <var>skip_host</var> or <var>skip_accept_encoding</var> |
| 131 | with non-False values. |
| 132 | |
| 133 | <span class="versionnote">Changed in version 2.4: |
| 134 | <var>skip_accept_encoding</var> argument added.</span> |
| 135 | |
| 136 | </dl> |
| 137 | |
| 138 | <P> |
| 139 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 140 | <td><nobr><b><tt id='l2h-3322' xml:id='l2h-3322' class="method">putheader</tt></b>(</nobr></td> |
| 141 | <td><var>header, argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt> |
| 142 | <dd> |
| 143 | Send an <a class="rfc" id='rfcref-90106' xml:id='rfcref-90106' |
| 144 | href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>-style header to the server. It sends a line to the |
| 145 | server consisting of the header, a colon and a space, and the first |
| 146 | argument. If more arguments are given, continuation lines are sent, |
| 147 | each consisting of a tab and an argument. |
| 148 | </dl> |
| 149 | |
| 150 | <P> |
| 151 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 152 | <td><nobr><b><tt id='l2h-3323' xml:id='l2h-3323' class="method">endheaders</tt></b>(</nobr></td> |
| 153 | <td><var></var>)</td></tr></table></dt> |
| 154 | <dd> |
| 155 | Send a blank line to the server, signalling the end of the headers. |
| 156 | </dl> |
| 157 | |
| 158 | <P> |
| 159 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 160 | <td><nobr><b><tt id='l2h-3324' xml:id='l2h-3324' class="method">send</tt></b>(</nobr></td> |
| 161 | <td><var>data</var>)</td></tr></table></dt> |
| 162 | <dd> |
| 163 | Send data to the server. This should be used directly only after the |
| 164 | <tt class="method">endheaders()</tt> method has been called and before |
| 165 | <tt class="method">getresponse()</tt> is called. |
| 166 | </dl> |
| 167 | |
| 168 | <P> |
| 169 | |
| 170 | <DIV CLASS="navigation"> |
| 171 | <div class='online-navigation'> |
| 172 | <p></p><hr /> |
| 173 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 174 | <tr> |
| 175 | <td class='online-navigation'><a rel="prev" title="11.6 httplib " |
| 176 | href="module-httplib.html"><img src='../icons/previous.png' |
| 177 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 178 | <td class='online-navigation'><a rel="parent" title="11.6 httplib " |
| 179 | href="module-httplib.html"><img src='../icons/up.png' |
| 180 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 181 | <td class='online-navigation'><a rel="next" title="11.6.2 HTTPResponse Objects" |
| 182 | href="httpresponse-objects.html"><img src='../icons/next.png' |
| 183 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 184 | <td align="center" width="100%">Python Library Reference</td> |
| 185 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 186 | href="contents.html"><img src='../icons/contents.png' |
| 187 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 188 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 189 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 190 | <td class='online-navigation'><a rel="index" title="Index" |
| 191 | href="genindex.html"><img src='../icons/index.png' |
| 192 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 193 | </tr></table> |
| 194 | <div class='online-navigation'> |
| 195 | <b class="navlabel">Previous:</b> |
| 196 | <a class="sectref" rel="prev" href="module-httplib.html">11.6 httplib </A> |
| 197 | <b class="navlabel">Up:</b> |
| 198 | <a class="sectref" rel="parent" href="module-httplib.html">11.6 httplib </A> |
| 199 | <b class="navlabel">Next:</b> |
| 200 | <a class="sectref" rel="next" href="httpresponse-objects.html">11.6.2 HTTPResponse Objects</A> |
| 201 | </div> |
| 202 | </div> |
| 203 | <hr /> |
| 204 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 205 | </DIV> |
| 206 | <!--End of Navigation Panel--> |
| 207 | <ADDRESS> |
| 208 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 209 | </ADDRESS> |
| 210 | </BODY> |
| 211 | </HTML> |