~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qhttp.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-10-12 23:14:14 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20061012231414-y2oqbom5dy389os0
Tags: upstream-4.2.0
ImportĀ upstreamĀ versionĀ 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/src/network/qhttp.cpp -->
6
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/src/network/qhttp.cpp -->
 
5
<!-- /tmp/qt-4.2.0-qt-1159540607313/qt-x11-opensource-src-4.2.0/src/network/qhttp.cpp -->
7
6
<head>
8
 
    <title>Qt 4.1: QHttp Class Reference</title>
9
 
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
10
 
a:link { color: #004faf; text-decoration: none }
11
 
a:visited { color: #672967; text-decoration: none }
12
 
td.postheader { font-family: sans-serif }
13
 
tr.address { font-family: sans-serif }
14
 
body { background: #ffffff; color: black; }</style>
 
7
  <title>Qt 4.2: QHttp Class Reference</title>
 
8
  <link href="classic.css" rel="stylesheet" type="text/css" />
15
9
</head>
16
10
<body>
17
11
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
12
<tr>
19
 
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
13
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
20
14
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
21
 
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QHttp Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1>
 
15
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QHttp Class Reference<br /><sup><sup>[<a href="qtnetwork.html">QtNetwork</a> module]</sup></sup></h1>
22
16
<p>The QHttp class provides an implementation of the HTTP protocol. <a href="#details">More...</a></p>
23
 
<pre>#include &lt;QHttp&gt;</pre><p>Inherits <a href="qobject.html">QObject</a>.</p>
 
17
<pre> #include &lt;QHttp&gt;</pre><p>Inherits <a href="qobject.html">QObject</a>.</p>
24
18
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
25
19
<ul>
26
20
<li><a href="qhttp-members.html">List of all members, including inherited members</a></li>
65
59
<li><div class="fn"/>State <b><a href="qhttp.html#state">state</a></b> () const</li>
66
60
</ul>
67
61
<ul>
68
 
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
62
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
69
63
</ul>
70
64
<a name="public-slots"></a>
71
65
<h3>Public Slots</h3>
93
87
<h3>Additional Inherited Members</h3>
94
88
<ul>
95
89
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
96
 
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
90
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
97
91
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
98
92
</ul>
99
93
<a name="details"></a>
104
98
<p>The class works asynchronously, so there are no blocking functions. If an operation cannot be executed immediately, the function will still return straight away and the operation will be scheduled for later execution. The results of scheduled operations are reported via signals. This approach depends on the event loop being in operation.</p>
105
99
<p>The operations that can be scheduled (they are called &quot;requests&quot; in the rest of the documentation) are the following: <a href="qhttp.html#setHost">setHost</a>(), <a href="qhttp.html#get">get</a>(), <a href="qhttp.html#post">post</a>(), <a href="qhttp.html#head">head</a>() and <a href="qhttp.html#request">request</a>().</p>
106
100
<p>All of these requests return a unique identifier that allows you to keep track of the request that is currently executed. When the execution of a request starts, the <a href="qhttp.html#requestStarted">requestStarted</a>() signal with the identifier is emitted and when the request is finished, the <a href="qhttp.html#requestFinished">requestFinished</a>() signal is emitted with the identifier and a bool that indicates if the request finished with an error.</p>
107
 
<p>To make an HTTP request you must set up suitable HTTP headers. The following example demonstrates, how to request the main HTML page from the Trolltech home page (i.e. the URL <tt>http://www.trolltech.com/index.html</tt>):</p>
108
 
<pre>&nbsp;   QHttpRequestHeader header(&quot;GET&quot;, &quot;/index.html&quot;);
109
 
    header.setValue(&quot;Host&quot;, &quot;www.trolltech.com&quot;);
110
 
    http-&gt;setHost(&quot;www.trolltech.com&quot;);
111
 
    http-&gt;request(header);</pre>
 
101
<p>To make an HTTP request you must set up suitable HTTP headers. The following example demonstrates, how to request the main HTML page from the Trolltech home page (i.e. the URL <tt>http:<span class="comment">//www.trolltech.com/index.html</span></tt>):</p>
 
102
<pre> QHttpRequestHeader header(&quot;GET&quot;, &quot;/index.html&quot;);
 
103
 header.setValue(&quot;Host&quot;, &quot;www.trolltech.com&quot;);
 
104
 http-&gt;setHost(&quot;www.trolltech.com&quot;);
 
105
 http-&gt;request(header);</pre>
112
106
<p>For the common HTTP requests <tt>GET</tt>, <tt>POST</tt> and <tt>HEAD</tt>, QHttp provides the convenience functions <a href="qhttp.html#get">get</a>(), <a href="qhttp.html#post">post</a>() and <a href="qhttp.html#head">head</a>(). They already use a reasonable header and if you don't have to set special header fields, they are easier to use. The above example can also be written as:</p>
113
 
<pre>&nbsp;   http-&gt;setHost(&quot;www.trolltech.com&quot;); // id == 1
114
 
    http-&gt;get(&quot;/index.html&quot;);           // id == 2</pre>
 
107
<pre> http-&gt;setHost(&quot;www.trolltech.com&quot;); <span class="comment">// id == 1</span>
 
108
 http-&gt;get(&quot;/index.html&quot;);           <span class="comment">// id == 2</span></pre>
115
109
<p>For this example the following sequence of signals is emitted (with small variations, depending on network traffic, etc.):</p>
116
 
<pre>&nbsp;   requestStarted(1)
117
 
    requestFinished(1, false)
118
 
 
119
 
    requestStarted(2)
120
 
    stateChanged(Connecting)
121
 
    stateChanged(Sending)
122
 
    dataSendProgress(77, 77)
123
 
    stateChanged(Reading)
124
 
    responseHeaderReceived(responseheader)
125
 
    dataReadProgress(5388, 0)
126
 
    readyRead(responseheader)
127
 
    dataReadProgress(18300, 0)
128
 
    readyRead(responseheader)
129
 
    stateChanged(Connected)
130
 
    requestFinished(2, false)
131
 
 
132
 
    done(false)
133
 
 
134
 
    stateChanged(Closing)
135
 
    stateChanged(Unconnected)</pre>
 
110
<pre> requestStarted(1)
 
111
 requestFinished(1, false)
 
112
 
 
113
 requestStarted(2)
 
114
 stateChanged(Connecting)
 
115
 stateChanged(Sending)
 
116
 dataSendProgress(77, 77)
 
117
 stateChanged(Reading)
 
118
 responseHeaderReceived(responseheader)
 
119
 dataReadProgress(5388, 0)
 
120
 readyRead(responseheader)
 
121
 dataReadProgress(18300, 0)
 
122
 readyRead(responseheader)
 
123
 stateChanged(Connected)
 
124
 requestFinished(2, false)
 
125
 
 
126
 done(false)
 
127
 
 
128
 stateChanged(Closing)
 
129
 stateChanged(Unconnected)</pre>
136
130
<p>The <a href="qhttp.html#dataSendProgress">dataSendProgress</a>() and <a href="qhttp.html#dataReadProgress">dataReadProgress</a>() signals in the above example are useful if you want to show a <a href="qprogressbar.html">progressbar</a> to inform the user about the progress of the download. The second argument is the total size of data. In certain cases it is not possible to know the total amount in advance, in which case the second argument is 0. (If you connect to a <a href="qprogressbar.html">QProgressBar</a> a total of 0 results in a busy indicator.)</p>
137
131
<p>When the response header is read, it is reported with the <a href="qhttp.html#responseHeaderReceived">responseHeaderReceived</a>() signal.</p>
138
132
<p>The <a href="qhttp.html#readyRead">readyRead</a>() signal tells you that there is data ready to be read. The amount of data can then be queried with the <a href="qhttp.html#bytesAvailable">bytesAvailable</a>() function and it can be read with the <a href="qhttp.html#read">read</a>() or <a href="qhttp.html#readAll">readAll</a>() functions.</p>
139
133
<p>If an error occurs during the execution of one of the commands in a sequence of commands, all the pending commands (i.e. scheduled, but not yet executed commands) are cleared and no signals are emitted for them.</p>
140
134
<p>For example, if you have the following sequence of requests</p>
141
 
<pre>&nbsp;   http-&gt;setHost(&quot;www.foo.bar&quot;);       // id == 1
142
 
    http-&gt;get(&quot;/index.html&quot;);           // id == 2
143
 
    http-&gt;post(&quot;register.html&quot;, data);  // id == 3</pre>
 
135
<pre> http-&gt;setHost(&quot;www.foo.bar&quot;);       <span class="comment">// id == 1</span>
 
136
 http-&gt;get(&quot;/index.html&quot;);           <span class="comment">// id == 2</span>
 
137
 http-&gt;post(&quot;register.html&quot;, data);  <span class="comment">// id == 3</span></pre>
144
138
<p>and the <a href="qhttp.html#get">get</a>() request fails because the host lookup fails, then the <a href="qhttp.html#post">post</a>() request is never executed and the signals would look like this:</p>
145
 
<pre>&nbsp;   requestStarted(1)
146
 
    requestFinished(1, false)
147
 
 
148
 
    requestStarted(2)
149
 
    stateChanged(HostLookup)
150
 
    requestFinished(2, true)
151
 
 
152
 
    done(true)
153
 
 
154
 
    stateChanged(Unconnected)</pre>
 
139
<pre> requestStarted(1)
 
140
 requestFinished(1, false)
 
141
 
 
142
 requestStarted(2)
 
143
 stateChanged(HostLookup)
 
144
 requestFinished(2, true)
 
145
 
 
146
 done(true)
 
147
 
 
148
 stateChanged(Unconnected)</pre>
155
149
<p>You can then get details about the error with the <a href="qhttp.html#error">error</a>() and <a href="qhttp.html#errorString">errorString</a>() functions. Note that only unexpected behavior, like network failure is considered as an error. If the server response contains an error status, like a 404 response, this is reported as a normal response case. So you should always check the <a href="qhttpresponseheader.html#statusCode">status code</a> of the response header.</p>
156
150
<p>The functions <a href="qhttp.html#currentId">currentId</a>() and <a href="qhttp.html#currentRequest">currentRequest</a>() provide more information about the currently executing request.</p>
157
151
<p>The functions <a href="qhttp.html#hasPendingRequests">hasPendingRequests</a>() and <a href="qhttp.html#clearPendingRequests">clearPendingRequests</a>() allow you to query and clear the list of pending requests.</p>
158
 
<p>The <a href="network-http.html">HTTP</a> example illustrates how to write HTTP clients using QHttp.</p>
159
 
<p>See also <a href="qftp.html">QFtp</a>.</p>
 
152
<p>See also <a href="qftp.html">QFtp</a>, <a href="network-http.html">HTTP Example</a>, and <a href="network-torrent.html">Torrent Example</a>.</p>
160
153
<hr />
161
154
<h2>Member Type Documentation</h2>
162
155
<h3 class="fn"><a name="Error-enum"></a>enum QHttp::Error</h3>
248
241
<p>Returns a human-readable description of the last error that occurred. This is useful to present a error message to the user when receiving a <a href="qhttp.html#requestFinished">requestFinished</a>() or a <a href="qhttp.html#done">done</a>() signal with the <tt>error</tt> argument <tt>true</tt>.</p>
249
242
<h3 class="fn"><a name="get"></a>int QHttp::get ( const <a href="qstring.html">QString</a> &amp; <i>path</i>, <a href="qiodevice.html">QIODevice</a> * <i>to</i> = 0 )</h3>
250
243
<p>Sends a get request for <i>path</i> to the server set by <a href="qhttp.html#setHost">setHost</a>() or as specified in the constructor.</p>
251
 
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http://www.trolltech.com/index.html</tt>.</p>
 
244
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http:<span class="comment">//www.trolltech.com/index.html</span></tt>.</p>
252
245
<p>If the IO device <i>to</i> is 0 the <a href="qhttp.html#readyRead">readyRead</a>() signal is emitted every time new content data is available to read.</p>
253
246
<p>If the IO device <i>to</i> is not 0, the content data of the response is written directly to the device. Make sure that the <i>to</i> pointer is valid for the duration of the operation (it is safe to delete it when the <a href="qhttp.html#requestFinished">requestFinished</a>() signal is emitted).</p>
254
247
<p>The function does not block and returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by <a href="qhttp.html#requestStarted">requestStarted</a>() and <a href="qhttp.html#requestFinished">requestFinished</a>().</p>
260
253
<p>See also <a href="qhttp.html#clearPendingRequests">clearPendingRequests</a>(), <a href="qhttp.html#currentId">currentId</a>(), and <a href="qhttp.html#currentRequest">currentRequest</a>().</p>
261
254
<h3 class="fn"><a name="head"></a>int QHttp::head ( const <a href="qstring.html">QString</a> &amp; <i>path</i> )</h3>
262
255
<p>Sends a header request for <i>path</i> to the server set by <a href="qhttp.html#setHost">setHost</a>() or as specified in the constructor.</p>
263
 
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http://www.trolltech.com/index.html</tt>.</p>
 
256
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http:<span class="comment">//www.trolltech.com/index.html</span></tt>.</p>
264
257
<p>The function does not block and returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by <a href="qhttp.html#requestStarted">requestStarted</a>() and <a href="qhttp.html#requestFinished">requestFinished</a>().</p>
265
258
<p>When the request is started the <a href="qhttp.html#requestStarted">requestStarted</a>() signal is emitted. When it is finished the <a href="qhttp.html#requestFinished">requestFinished</a>() signal is emitted.</p>
266
259
<p>See also <a href="qhttp.html#setHost">setHost</a>(), <a href="qhttp.html#get">get</a>(), <a href="qhttp.html#post">post</a>(), <a href="qhttp.html#request">request</a>(), <a href="qhttp.html#requestStarted">requestStarted</a>(), <a href="qhttp.html#requestFinished">requestFinished</a>(), and <a href="qhttp.html#done">done</a>().</p>
269
262
<p>See also <a href="qhttp.html#currentRequest">currentRequest</a>().</p>
270
263
<h3 class="fn"><a name="post"></a>int QHttp::post ( const <a href="qstring.html">QString</a> &amp; <i>path</i>, <a href="qiodevice.html">QIODevice</a> * <i>data</i>, <a href="qiodevice.html">QIODevice</a> * <i>to</i> = 0 )</h3>
271
264
<p>Sends a post request for <i>path</i> to the server set by <a href="qhttp.html#setHost">setHost</a>() or as specified in the constructor.</p>
272
 
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http://www.trolltech.com/index.html</tt>.</p>
 
265
<p><i>path</i> must be an absolute path like <tt>/index.html</tt> or an absolute URI like <tt>http:<span class="comment">//www.trolltech.com/index.html</span></tt>.</p>
273
266
<p>The incoming data comes via the <i>data</i> IO device.</p>
274
267
<p>If the IO device <i>to</i> is 0 the <a href="qhttp.html#readyRead">readyRead</a>() signal is emitted every time new content data is available to read.</p>
275
268
<p>If the IO device <i>to</i> is not 0, the content data of the response is written directly to the device. Make sure that the <i>to</i> pointer is valid for the duration of the operation (it is safe to delete it when the <a href="qhttp.html#requestFinished">requestFinished</a>() signal is emitted).</p>
320
313
<h3 class="fn"><a name="setProxy"></a>int QHttp::setProxy ( const <a href="qstring.html">QString</a> &amp; <i>host</i>, int <i>port</i>, const <a href="qstring.html">QString</a> &amp; <i>username</i> = QString(), const <a href="qstring.html">QString</a> &amp; <i>password</i> = QString() )</h3>
321
314
<p>Enables HTTP proxy support, using the proxy server <i>host</i> on port <i>port</i>. <i>username</i> and <i>password</i> can be provided if the proxy server requires authentication.</p>
322
315
<p>Example:</p>
323
 
<pre>&nbsp;   void Ticker::getTicks()
324
 
    {
325
 
      http = new QHttp(this);
326
 
      connect(http, SIGNAL(done(bool)), this, SLOT(showPage()));
327
 
      http-&gt;setProxy(&quot;proxy.example.com&quot;, 3128);
328
 
      http-&gt;setHost(&quot;ticker.example.com&quot;);
329
 
      http-&gt;get(&quot;/ticks.asp&quot;);
330
 
    }
 
316
<pre> void Ticker::getTicks()
 
317
 {
 
318
   http = new QHttp(this);
 
319
   connect(http, SIGNAL(done(bool)), this, SLOT(showPage()));
 
320
   http-&gt;setProxy(&quot;proxy.example.com&quot;, 3128);
 
321
   http-&gt;setHost(&quot;ticker.example.com&quot;);
 
322
   http-&gt;get(&quot;/ticks.asp&quot;);
 
323
 }
331
324
 
332
 
    void Ticker::showPage()
333
 
    {
334
 
      display(http-&gt;readAll());
335
 
    }</pre>
 
325
 void Ticker::showPage()
 
326
 {
 
327
   display(http-&gt;readAll());
 
328
 }</pre>
336
329
<p><a href="qhttp.html">QHttp</a> supports non-transparent web proxy servers only, such as the Squid Web proxy cache server (from <a href="http://www.squid.org/">http://www.squid.org/</a>). For transparent proxying, such as SOCKS5, use <a href="qnetworkproxy.html">QNetworkProxy</a> instead.</p>
337
330
<p>See also <a href="qftp.html#setProxy">QFtp::setProxy</a>().</p>
338
331
<h3 class="fn"><a name="setSocket"></a>int QHttp::setSocket ( <a href="qtcpsocket.html">QTcpSocket</a> * <i>socket</i> )</h3>
352
345
<p>This signal is emitted when the state of the <a href="qhttp.html">QHttp</a> object changes. The argument <i>state</i> is the new state of the connection; it is one of the <a href="qhttp.html#State-enum">State</a> values.</p>
353
346
<p>This usually happens when a request is started, but it can also happen when the server closes the connection or when a call to <a href="qhttp.html#close">close</a>() succeeded.</p>
354
347
<p>See also <a href="qhttp.html#get">get</a>(), <a href="qhttp.html#post">post</a>(), <a href="qhttp.html#head">head</a>(), <a href="qhttp.html#request">request</a>(), <a href="qhttp.html#close">close</a>(), <a href="qhttp.html#state">state</a>(), and <a href="qhttp.html#State-enum">State</a>.</p>
 
348
<hr />
 
349
<h2>Member Function Documentation</h2>
 
350
<h3 class="fn"><a name="readBlock"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QHttp::readBlock ( char * <i>data</i>, <a href="qtglobal.html#quint64-typedef">quint64</a> <i>maxlen</i> )</h3>
 
351
<p>Use <a href="qhttp.html#read">read</a>() instead.</p>
355
352
<p /><address><hr /><div align="center">
356
353
<table width="100%" cellspacing="0" border="0"><tr class="address">
357
354
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
358
355
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
359
 
<td width="30%" align="right"><div align="right">Qt 4.1.4</div></td>
 
356
<td width="30%" align="right"><div align="right">Qt 4.2.0</div></td>
360
357
</tr></table></div></address></body>
361
358
</html>