|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.network.QHttp
public class QHttp
The QHttp class provides an implementation of the HTTP protocol. This class provides a direct interface to HTTP that allows you to have more control over the requests and that allows you to access the response header fields. However, for new applications, it is recommended to use QNetworkAccessManager
and QNetworkReply
, as those classes possess a simpler, yet more powerful API.
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.
The operations that can be scheduled (they are called "requests" in the rest of the documentation) are the following: setHost()
, get()
, post()
, head()
and request()
.
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 requestStarted()
signal with the identifier is emitted and when the request is finished, the requestFinished()
signal is emitted with the identifier and a bool that indicates if the request finished with an error.
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 http://qtsoftware.com/index.html):
QHttp http = new QHttp(); QHttpRequestHeader header = new QHttpRequestHeader("GET", "/index.html"); header.setValue("Host", "www.trolltech.com"); http.setHost("www.trolltech.com", 80); http.request(header);For the common HTTP requests GET, POST and HEAD, QHttp provides the convenience functions
get()
, post()
and head()
. 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: http.setHost("www.trolltech.com", 80); // id == 1 http.get("/index.html"); // id == 2For this example the following sequence of signals is emitted (with small variations, depending on network traffic, etc.):
requestStarted(1) requestFinished(1, false) requestStarted(2) stateChanged(Connecting) stateChanged(Sending) dataSendProgress(77, 77) stateChanged(Reading) responseHeaderReceived(responseheader) dataReadProgress(5388, 0) readyRead(responseheader) dataReadProgress(18300, 0) readyRead(responseheader) stateChanged(Connected) requestFinished(2, false) done(false) stateChanged(Closing) stateChanged(Unconnected)The
dataSendProgress()
and dataReadProgress()
signals in the above example are useful if you want to show a progress bar
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 QProgressBar
a total of 0 results in a busy indicator.) When the response header is read, it is reported with the responseHeaderReceived()
signal.
The readyRead()
signal tells you that there is data ready to be read. The amount of data can then be queried with the bytesAvailable()
function and it can be read with the read()
or readAll()
functions.
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.
For example, if you have the following sequence of requests
http.setHost("www.foo.bar", 80); // id == 1 http.get("/index.html"); // id == 2 http.post("register.html", data); // id == 3and the
get()
request fails because the host lookup fails, then the post()
request is never executed and the signals would look like this: requestStarted(1) requestFinished(1, false) requestStarted(2) stateChanged(HostLookup) requestFinished(2, true) done(true) stateChanged(Unconnected)You can then get details about the error with the
error()
and errorString()
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 status code
of the response header. The functions currentId()
and currentRequest()
provide more information about the currently executing request.
The functions hasPendingRequests()
and clearPendingRequests()
allow you to query and clear the list of pending requests.
QFtp
, QNetworkAccessManager
, QNetworkRequest
, QNetworkReply
, HTTP Example, and Torrent Example.
Nested Class Summary | |
---|---|
static class |
QHttp.ConnectionMode
This enum is used to specify the mode of connection to use. |
static class |
QHttp.Error
This enum identifies the error that occurred. |
static class |
QHttp.State
This enum is used to specify the state the client is in. |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal3 |
authenticationRequired
This signal takes 3 generic argument(s). |
QSignalEmitter.Signal2 |
dataReadProgress
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
dataSendProgress
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
done
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal2 |
proxyAuthenticationRequired
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
readyRead
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal2 |
requestFinished
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
requestStarted
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
responseHeaderReceived
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
sslErrors
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
stateChanged
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QHttp()
Constructs a QHttp object. |
|
QHttp(QObject parent)
Constructs a QHttp object. |
|
QHttp(java.lang.String hostname)
Constructs a QHttp object. |
|
QHttp(java.lang.String hostname,
int port)
This is an overloaded constructor provided for convenince. |
|
QHttp(java.lang.String hostname,
int port,
QObject parent)
This is an overloaded constructor provided for convenince. |
|
QHttp(java.lang.String hostname,
QHttp.ConnectionMode mode)
Constructs a QHttp object. |
|
QHttp(java.lang.String hostname,
QHttp.ConnectionMode mode,
int port)
Constructs a QHttp object. |
|
QHttp(java.lang.String hostname,
QHttp.ConnectionMode mode,
int port,
QObject parent)
Constructs a QHttp object. |
Method Summary | |
---|---|
void |
abort()
Aborts the current request and deletes all scheduled requests. |
long |
bytesAvailable()
Returns the number of bytes that can be read from the response content at the moment. |
void |
clearPendingRequests()
Deletes all pending requests from the list of scheduled requests. |
int |
close()
Closes the connection; this is useful if you have a keep-alive connection and want to close it. |
QIODevice |
currentDestinationDevice()
Returns the QIODevice pointer that is used as to store the data of the HTTP request being executed. |
int |
currentId()
Returns the identifier of the HTTP request being executed or 0 if there is no request being executed (i. |
QHttpRequestHeader |
currentRequest()
Returns the request header of the HTTP request being executed. |
QIODevice |
currentSourceDevice()
Returns the QIODevice pointer that is used as the data source of the HTTP request being executed. |
QHttp.Error |
error()
Returns the last error that occurred. |
java.lang.String |
errorString()
Returns a human-readable description of the last error that occurred. |
int |
get(java.lang.String path)
Sends a get request for path to the server set by setHost() or as specified in the constructor. |
int |
get(java.lang.String path,
QIODevice to)
Sends a get request for path to the server set by setHost() or as specified in the constructor. |
boolean |
hasPendingRequests()
Returns true if there are any requests scheduled that have not yet been executed; otherwise returns false. |
int |
head(java.lang.String path)
Sends a header request for path to the server set by setHost() or as specified in the constructor. |
void |
ignoreSslErrors()
Tells the QSslSocket used for the Http connection to ignore the errors reported in the sslErrors() signal. |
QHttpResponseHeader |
lastResponse()
Returns the received response header of the most recently finished HTTP request. |
int |
post(java.lang.String path,
QByteArray data)
This is an overloaded member function, provided for convenience. |
int |
post(java.lang.String path,
QByteArray data,
QIODevice to)
This is an overloaded member function, provided for convenience. |
int |
post(java.lang.String path,
QIODevice data)
Sends a post request for path to the server set by setHost() or as specified in the constructor. |
int |
post(java.lang.String path,
QIODevice data,
QIODevice to)
Sends a post request for path to the server set by setHost() or as specified in the constructor. |
int |
read(byte[] data)
Reads from this http connection into data. |
QByteArray |
readAll()
Reads all the bytes from the response content and returns them. |
int |
request(QHttpRequestHeader header)
Sends a request to the server set by setHost() or as specified in the constructor. |
int |
request(QHttpRequestHeader header,
QByteArray data)
This is an overloaded member function, provided for convenience. |
int |
request(QHttpRequestHeader header,
QByteArray data,
QIODevice to)
This is an overloaded member function, provided for convenience. |
int |
request(QHttpRequestHeader header,
QIODevice device)
Sends a request to the server set by setHost() or as specified in the constructor. |
int |
request(QHttpRequestHeader header,
QIODevice device,
QIODevice to)
Sends a request to the server set by setHost() or as specified in the constructor. |
int |
setHost(java.lang.String hostname)
Sets the HTTP server that is used for requests to hostName on port port. |
int |
setHost(java.lang.String hostname,
int port)
Sets the HTTP server that is used for requests to hostname on port port. |
int |
setHost(java.lang.String hostName,
QHttp.ConnectionMode mode)
Sets the HTTP server that is used for requests to hostName on port port using the connection mode mode. |
int |
setHost(java.lang.String hostname,
QHttp.ConnectionMode mode,
int port)
Sets the HTTP server that is used for requests to hostName on port port using the connection mode mode. |
int |
setProxy(QNetworkProxy proxy)
This is an overloaded member function, provided for convenience. |
int |
setProxy(java.lang.String host,
int port)
Enables HTTP proxy support, using the proxy server host on port port. |
int |
setProxy(java.lang.String host,
int port,
java.lang.String username)
Enables HTTP proxy support, using the proxy server host on port port. |
int |
setProxy(java.lang.String host,
int port,
java.lang.String username,
java.lang.String password)
Enables HTTP proxy support, using the proxy server host on port port. |
int |
setSocket(QTcpSocket socket)
Replaces the internal QTcpSocket that QHttp uses with socket. |
int |
setUser(java.lang.String username)
This function sets the user name userName and password password for web pages that require authentication. |
int |
setUser(java.lang.String username,
java.lang.String password)
This function sets the user name userName and password password for web pages that require authentication. |
QHttp.State |
state()
Returns the current state of the object. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal2 dataReadProgress
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: done), java.lang.Integer(named: total)>:
This signal is emitted when this object reads data from a HTTP server to indicate the current progress of the download.
done is the amount of data that has already arrived and total is the total amount of data. It is possible that the total amount of data that should be transferred cannot be determined, in which case total is 0.(If you connect to a QProgressBar
, the progress bar shows a busy indicator if the total is 0).
Warning:done and total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow.
dataSendProgress()
, get()
, post()
, request()
, and QProgressBar
.
public final QSignalEmitter.Signal2 dataSendProgress
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: done), java.lang.Integer(named: total)>:
This signal is emitted when this object sends data to a HTTP server to inform it about the progress of the upload.
done is the amount of data that has already arrived and total is the total amount of data. It is possible that the total amount of data that should be transferred cannot be determined, in which case total is 0.(If you connect to a QProgressBar
, the progress bar shows a busy indicator if the total is 0).
Warning:done and total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow.
dataReadProgress()
, post()
, request()
, and QProgressBar
.
public final QSignalEmitter.Signal1 done
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: error)>:
This signal is emitted when the last pending request has finished; (it is emitted after the last request's requestFinished()
signal). error is true if an error occurred during the processing; otherwise error is false.
requestFinished()
, error()
, and errorString()
.
public final QSignalEmitter.Signal1 readyRead
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.network.QHttpResponseHeader(named: resp)>:
This signal is emitted when there is new response data to read.
If you specified a device in the request where the data should be written to, then this signal is not emitted; instead the data is written directly to the device.
The response header is passed in resp.
You can read the data with the readAll()
or read()
functions
This signal is useful if you want to process the data in chunks as soon as it becomes available. If you are only interested in the complete data, just connect to the requestFinished()
signal and read the data then instead.
get()
, post()
, request()
, readAll()
, read()
, and bytesAvailable()
.
public final QSignalEmitter.Signal2 requestFinished
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: id), java.lang.Boolean(named: error)>:
This signal is emitted when processing the request identified by id has finished. error is true if an error occurred during the processing; otherwise error is false.
requestStarted()
, done()
, error()
, and errorString()
.
public final QSignalEmitter.Signal1 requestStarted
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: id)>:
This signal is emitted when processing the request identified by id starts.
requestFinished()
, and done()
.
public final QSignalEmitter.Signal1 responseHeaderReceived
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.network.QHttpResponseHeader(named: resp)>:
This signal is emitted when the HTTP header of a server response is available. The header is passed in resp.
get()
, post()
, head()
, request()
, and readyRead()
.
public final QSignalEmitter.Signal1 sslErrors
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.util.List Forwards the sslErrors signal from the
QSslSocket
used in QHttp. errors is the list of errors that occurred during the SSL handshake. Unless you call ignoreSslErrors()
from within a slot connected to this signal when an error occurs, QHttp will tear down the connection immediately after emitting the signal. QSslSocket
, and QSslSocket::ignoreSslErrors()
.
public final QSignalEmitter.Signal1 stateChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: state)>:
This signal is emitted when the state of the QHttp object changes. The argument state is the new state of the connection; it is one of the State
values.
This usually happens when a request is started, but it can also happen when the server closes the connection or when a call to close()
succeeded.
get()
, post()
, head()
, request()
, close()
, state()
, and State
.
public QSignalEmitter.Signal2 proxyAuthenticationRequired
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.network.QNetworkProxy(named: proxy), com.trolltech.qt.network.QAuthenticator(named: authenticator)>:
This signal can be emitted when a proxy that requires authentication is used. The authenticator object can then be filled in with the required details to allow authentication and continue the connection.
Note: It is not possible to use a QueuedConnection to connect to this signal, as the connection will fail if the authenticator has not been filled in with new information when the signal returns.
QAuthenticator
, and QNetworkProxy
.
public QSignalEmitter.Signal3 authenticationRequired
This signal takes 3 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: hostname), java.lang.Integer(named: port), com.trolltech.qt.network.QAuthenticator(named: authenticator)>:
This signal can be emitted when a web server on a given hostname and port requires authentication. The authenticator object can then be filled in with the required details to allow authentication and continue the connection.
Note: It is not possible to use a QueuedConnection to connect to this signal, as the connection will fail if the authenticator has not been filled in with new information when the signal returns.
QAuthenticator
, and QNetworkProxy
.
Constructor Detail |
---|
public QHttp()
QObject
constructor.
public QHttp(QObject parent)
QObject
constructor.
public QHttp(java.lang.String hostname)
If port is 0, it will use the default port for the mode used (80 for Http and 443 for Https).
The parent parameter is passed on to the QObject
constructor.
setHost()
.
public QHttp(java.lang.String hostname, int port)
public QHttp(java.lang.String hostname, int port, QObject parent)
public QHttp(java.lang.String hostname, QHttp.ConnectionMode mode)
If port is 0, it will use the default port for the mode used (80 for Http and 443 for Https).
The parent parameter is passed on to the QObject
constructor.
setHost()
.
public QHttp(java.lang.String hostname, QHttp.ConnectionMode mode, int port)
If port is 0, it will use the default port for the mode used (80 for Http and 443 for Https).
The parent parameter is passed on to the QObject
constructor.
setHost()
.
public QHttp(java.lang.String hostname, QHttp.ConnectionMode mode, int port, QObject parent)
If port is 0, it will use the default port for the mode used (80 for Http and 443 for Https).
The parent parameter is passed on to the QObject
constructor.
setHost()
.
Method Detail |
---|
public final void abort()
For the current request, the requestFinished()
signal with the error argument true is emitted. For all other requests that are affected by the abort()
, no signals are emitted.
Since this slot also deletes the scheduled requests, there are no requests left and the done()
signal is emitted (with the error argument true).
clearPendingRequests()
.
public final long bytesAvailable()
get()
, post()
, request()
, readyRead()
, read()
, and readAll()
.
public final void clearPendingRequests()
abort()
. hasPendingRequests()
, and abort()
.
public final int close()
For the requests issued with get()
, post()
and head()
, QHttp sets the connection to be keep-alive. You can also do this using the header you pass to the request()
function. QHttp only closes the connection to the HTTP server if the response header requires it to do so.
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
If you want to close the connection immediately, you have to use abort()
instead.
stateChanged()
, abort()
, requestStarted()
, requestFinished()
, and done()
.
public final QIODevice currentDestinationDevice()
QIODevice
pointer that is used as to store the data of the HTTP request being executed. If there is no current request or if the request does not store the data to an IO device, this function returns 0. This function can be used to delete the QIODevice
in the slot connected to the requestFinished()
signal.
currentSourceDevice()
, get()
, post()
, and request()
.
public final int currentId()
currentRequest()
.
public final QHttpRequestHeader currentRequest()
setHost()
or close()
, it returns an invalid request header, i.e. QHttpRequestHeader::isValid()
returns false. currentId()
.
public final QIODevice currentSourceDevice()
QIODevice
pointer that is used as the data source of the HTTP request being executed. If there is no current request or if the request does not use an IO device as the data source, this function returns 0. This function can be used to delete the QIODevice
in the slot connected to the requestFinished()
signal.
currentDestinationDevice()
, post()
, and request()
.
public final QHttp.Error error()
requestFinished()
or a done()
signal with the error argument true. If you start a new request, the error status is reset to NoError.
public final java.lang.String errorString()
requestFinished()
or a done()
signal with the error argument true.
public final int get(java.lang.String path)
setHost()
or as specified in the constructor. path must be a absolute path like /index.html or an absolute URI like http://qtsoftware.com/index.html and must be encoded with either QUrl::toPercentEncoding()
or QUrl::encodedPath()
.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).Request Processing
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, post()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int get(java.lang.String path, QIODevice to)
setHost()
or as specified in the constructor. path must be a absolute path like /index.html or an absolute URI like http://qtsoftware.com/index.html and must be encoded with either QUrl::toPercentEncoding()
or QUrl::encodedPath()
.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).Request Processing
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, post()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final boolean hasPendingRequests()
The request that is being executed is not considered as a scheduled request.
clearPendingRequests()
, currentId()
, and currentRequest()
.
public final int head(java.lang.String path)
setHost()
or as specified in the constructor. path must be an absolute path like /index.html or an absolute URI like http://qtsoftware.com/index.html.
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, post()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final void ignoreSslErrors()
QSslSocket
used for the Http connection to ignore the errors reported in the sslErrors()
signal. Note that this function must be called from within a slot connected to the sslErrors()
signal to have any effect.
QSslSocket
, and QSslSocket::sslErrors()
.
public final QHttpResponseHeader lastResponse()
QHttpResponseHeader::isValid()
will return false. currentRequest()
.
public final int post(java.lang.String path, QIODevice data)
setHost()
or as specified in the constructor. path must be an absolute path like /index.html or an absolute URI like http://qtsoftware.com/index.html and must be encoded with either QUrl::toPercentEncoding()
or QUrl::encodedPath()
.
The incoming data comes via the data IO device.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int post(java.lang.String path, QIODevice data, QIODevice to)
setHost()
or as specified in the constructor. path must be an absolute path like /index.html or an absolute URI like http://qtsoftware.com/index.html and must be encoded with either QUrl::toPercentEncoding()
or QUrl::encodedPath()
.
The incoming data comes via the data IO device.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int post(java.lang.String path, QByteArray data)
data is used as the content data of the HTTP request.
public final int post(java.lang.String path, QByteArray data, QIODevice to)
data is used as the content data of the HTTP request.
public final QByteArray readAll()
get()
, post()
, request()
, readyRead()
, bytesAvailable()
, and read()
.
public final int request(QHttpRequestHeader header, QIODevice device)
setHost()
or as specified in the constructor. Uses the header as the HTTP request header. You are responsible for setting up a header that is appropriate for your request. The incoming data comes via the data IO device.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, post()
, head()
, requestStarted()
, requestFinished()
, and done()
.
public final int request(QHttpRequestHeader header)
setHost()
or as specified in the constructor. Uses the header as the HTTP request header. You are responsible for setting up a header that is appropriate for your request. The incoming data comes via the data IO device.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, post()
, head()
, requestStarted()
, requestFinished()
, and done()
.
public final int request(QHttpRequestHeader header, QIODevice device, QIODevice to)
setHost()
or as specified in the constructor. Uses the header as the HTTP request header. You are responsible for setting up a header that is appropriate for your request. The incoming data comes via the data IO device.
If the IO device to is 0 the readyRead()
signal is emitted every time new content data is available to read.
If the IO device to is not 0, the content data of the response is written directly to the device. Make sure that the to pointer is valid for the duration of the operation (it is safe to delete it when the requestFinished()
signal is emitted).
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
setHost()
, get()
, post()
, head()
, requestStarted()
, requestFinished()
, and done()
.
public final int request(QHttpRequestHeader header, QByteArray data)
data is used as the content data of the HTTP request.
public final int request(QHttpRequestHeader header, QByteArray data, QIODevice to)
data is used as the content data of the HTTP request.
public final int setProxy(QNetworkProxy proxy)
Enables HTTP proxy support using the proxy settings from proxy. If proxy is a transparent proxy, QHttp will call QAbstractSocket::setProxy()
on the underlying socket. If the type is QNetworkProxy::HttpCachingProxy
, QHttp will behave like the previous function.
Note: for compatibility with Qt 4.3, if the proxy type is QNetworkProxy::HttpProxy
and the request type is unencrypted (that is, ConnectionModeHttp
), QHttp will treat the proxy as a caching proxy.
public final int setProxy(java.lang.String host, int port, java.lang.String username)
Example:
public void getTicks() { http = new QHttp(this); http.done.connect(this, "showPage()"); http.setProxy("proxy.example.com", 3128); http.setHost("ticker.example.com", 80); http.get("/ticks.asp"); } void showPage() { display(http.readAll()); }QHttp supports non-transparent web proxy servers only, such as the Squid Web proxy cache server (from http://www.squid.org/). For transparent proxying, such as SOCKS5, use
QNetworkProxy
instead. QFtp::setProxy()
.
public final int setProxy(java.lang.String host, int port)
Example:
public void getTicks() { http = new QHttp(this); http.done.connect(this, "showPage()"); http.setProxy("proxy.example.com", 3128); http.setHost("ticker.example.com", 80); http.get("/ticks.asp"); } void showPage() { display(http.readAll()); }QHttp supports non-transparent web proxy servers only, such as the Squid Web proxy cache server (from http://www.squid.org/). For transparent proxying, such as SOCKS5, use
QNetworkProxy
instead. QFtp::setProxy()
.
public final int setProxy(java.lang.String host, int port, java.lang.String username, java.lang.String password)
Example:
public void getTicks() { http = new QHttp(this); http.done.connect(this, "showPage()"); http.setProxy("proxy.example.com", 3128); http.setHost("ticker.example.com", 80); http.get("/ticks.asp"); } void showPage() { display(http.readAll()); }QHttp supports non-transparent web proxy servers only, such as the Squid Web proxy cache server (from http://www.squid.org/). For transparent proxying, such as SOCKS5, use
QNetworkProxy
instead. QFtp::setProxy()
.
public final int setSocket(QTcpSocket socket)
QTcpSocket
that QHttp uses with socket. This is useful if you want to use your own custom QTcpSocket
subclass instead of the plain QTcpSocket
that QHttp uses by default. QHttp does not take ownership of the socket, and will not delete socket when destroyed. The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
Note: If QHttp is used in a non-GUI thread that runs its own event loop, you must move socket to that thread before calling setSocket()
.
QObject::moveToThread()
, and Thread Support in Qt.
public final int setUser(java.lang.String username)
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
public final int setUser(java.lang.String username, java.lang.String password)
The function does not block; instead, it returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
public final QHttp.State state()
stateChanged()
signal is emitted. State
, and stateChanged()
.
public final int setHost(java.lang.String hostName, QHttp.ConnectionMode mode)
If port is 0, it will use the default port for the mode used (80 for Http and 443 fopr Https).
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 requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
get()
, post()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int setHost(java.lang.String hostname, QHttp.ConnectionMode mode, int port)
If port is 0, it will use the default port for the mode used (80 for Http and 443 fopr Https).
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 requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
get()
, post()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int setHost(java.lang.String hostname)
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 requestStarted()
and requestFinished()
.
When the request is started the requestStarted()
signal is emitted. When it is finished the requestFinished()
signal is emitted.
get()
, post()
, head()
, request()
, requestStarted()
, requestFinished()
, and done()
.
public final int setHost(java.lang.String hostname, int port)
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 requestStarted() and requestFinished().
When the request is started the requestStarted() signal is emitted. When it is finished the requestFinished() signal is emitted.
public final int read(byte[] data)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |