Qt 4.8
|
The QHttp class provides an implementation of the HTTP protocol. More...
#include <qhttp.h>
Public Types | |
enum | ConnectionMode { ConnectionModeHttp, ConnectionModeHttps } |
This enum is used to specify the mode of connection to use: More... | |
enum | Error { NoError, UnknownError, HostNotFound, ConnectionRefused, UnexpectedClose, InvalidResponseHeader, WrongContentLength, Aborted, AuthenticationRequiredError, ProxyAuthenticationRequiredError } |
This enum identifies the error that occurred. More... | |
enum | State { Unconnected, HostLookup, Connecting, Sending, Reading, Connected, Closing } |
This enum is used to specify the state the client is in: More... | |
Public Slots | |
void | abort () |
Aborts the current request and deletes all scheduled requests. More... | |
void | ignoreSslErrors () |
Tells the QSslSocket used for the Http connection to ignore the errors reported in the sslErrors() signal. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals | |
void | authenticationRequired (const QString &hostname, quint16 port, QAuthenticator *) |
void | dataReadProgress (int, int) |
This signal is emitted when this object reads data from a HTTP server to indicate the current progress of the download. More... | |
void | dataSendProgress (int, int) |
This signal is emitted when this object sends data to a HTTP server to inform it about the progress of the upload. More... | |
void | done (bool) |
This signal is emitted when the last pending request has finished; (it is emitted after the last request's requestFinished() signal). More... | |
void | proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *) |
void | readyRead (const QHttpResponseHeader &resp) |
This signal is emitted when there is new response data to read. More... | |
void | requestFinished (int, bool) |
This signal is emitted when processing the request identified by id has finished. More... | |
void | requestStarted (int) |
This signal is emitted when processing the request identified by id starts. More... | |
void | responseHeaderReceived (const QHttpResponseHeader &resp) |
This signal is emitted when the HTTP header of a server response is available. More... | |
void | sslErrors (const QList< QSslError > &errors) |
Forwards the sslErrors signal from the QSslSocket used in QHttp. More... | |
void | stateChanged (int) |
This signal is emitted when the state of the QHttp object changes. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
qint64 | bytesAvailable () const |
Returns the number of bytes that can be read from the response content at the moment. More... | |
void | clearPendingRequests () |
Deletes all pending requests from the list of scheduled requests. More... | |
int | close () |
Closes the connection; this is useful if you have a keep-alive connection and want to close it. More... | |
int | closeConnection () |
Behaves the same as close(). More... | |
QIODevice * | currentDestinationDevice () const |
Returns the QIODevice pointer that is used as to store the data of the HTTP request being executed. More... | |
int | currentId () const |
Returns the identifier of the HTTP request being executed or 0 if there is no request being executed (i.e. More... | |
QHttpRequestHeader | currentRequest () const |
Returns the request header of the HTTP request being executed. More... | |
QIODevice * | currentSourceDevice () const |
Returns the QIODevice pointer that is used as the data source of the HTTP request being executed. More... | |
Error | error () const |
Returns the last error that occurred. More... | |
QString | errorString () const |
Returns a human-readable description of the last error that occurred. More... | |
int | get (const QString &path, QIODevice *to=0) |
Sends a get request for path to the server set by setHost() or as specified in the constructor. More... | |
bool | hasPendingRequests () const |
Returns true if there are any requests scheduled that have not yet been executed; otherwise returns false. More... | |
int | head (const QString &path) |
Sends a header request for path to the server set by setHost() or as specified in the constructor. More... | |
QHttpResponseHeader | lastResponse () const |
Returns the received response header of the most recently finished HTTP request. More... | |
int | post (const QString &path, QIODevice *data, QIODevice *to=0) |
Sends a post request for path to the server set by setHost() or as specified in the constructor. More... | |
int | post (const QString &path, const QByteArray &data, QIODevice *to=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.data is used as the content data of the HTTP request. More... | |
QHttp (QObject *parent=0) | |
Constructs a QHttp object. More... | |
QHttp (const QString &hostname, quint16 port=80, QObject *parent=0) | |
Constructs a QHttp object. More... | |
QHttp (const QString &hostname, ConnectionMode mode, quint16 port=0, QObject *parent=0) | |
Constructs a QHttp object. More... | |
qint64 | read (char *data, qint64 maxlen) |
Reads maxlen bytes from the response content into data and returns the number of bytes read. More... | |
QByteArray | readAll () |
Reads all the bytes from the response content and returns them. More... | |
int | request (const QHttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0) |
Sends a request to the server set by setHost() or as specified in the constructor. More... | |
int | request (const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.data is used as the content data of the HTTP request. More... | |
int | setHost (const QString &hostname, quint16 port=80) |
Sets the HTTP server that is used for requests to hostName on port port. More... | |
int | setHost (const QString &hostname, ConnectionMode mode, quint16 port=0) |
Sets the HTTP server that is used for requests to hostName on port port using the connection mode mode. More... | |
int | setProxy (const QString &host, int port, const QString &username=QString(), const QString &password=QString()) |
Enables HTTP proxy support, using the proxy server host on port port. More... | |
int | setProxy (const QNetworkProxy &proxy) |
Enables HTTP proxy support using the proxy settings from proxy. More... | |
int | setSocket (QTcpSocket *socket) |
Replaces the internal QTcpSocket that QHttp uses with socket. More... | |
int | setUser (const QString &username, const QString &password=QString()) |
This function sets the user name userName and password password for web pages that require authentication. More... | |
State | state () const |
Returns the current state of the object. More... | |
virtual | ~QHttp () |
Destroys the QHttp object. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Friends | |
class | QHttpCloseRequest |
class | QHttpNormalRequest |
class | QHttpPGHRequest |
class | QHttpSetHostRequest |
class | QHttpSetProxyRequest |
class | QHttpSetSocketRequest |
class | QHttpSetUserRequest |
Additional Inherited Members | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QHttp class provides an implementation of the HTTP protocol.
This class provides a direct interface to HTTP that allows you to download and upload data with the HTTP protocol. However, for new applications, it is recommended to use QNetworkAccessManager and QNetworkReply, as those classes possess a simpler, yet more powerful API and a more modern protocol implementation.
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 Qt website (i.e., the URL http://qt.nokia.com/index.html
):
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:
For this example the following sequence of signals is emitted (with small variations, depending on network traffic, etc.):
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
and the get() request fails because the host lookup fails, then the post() request is never executed and the signals would look like this:
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.
This enum is used to specify the mode of connection to use:
When using the HTTPS mode, care should be taken to connect to the sslErrors signal, and handle possible SSL errors.
Enumerator | |
---|---|
ConnectionModeHttp | |
ConnectionModeHttps |
Definition at line 178 of file qhttp.h.
enum QHttp::Error |
This enum identifies the error that occurred.
Enumerator | |
---|---|
NoError | |
UnknownError | |
HostNotFound | |
ConnectionRefused | |
UnexpectedClose | |
InvalidResponseHeader | |
WrongContentLength | |
Aborted | |
AuthenticationRequiredError | |
ProxyAuthenticationRequiredError |
Definition at line 197 of file qhttp.h.
enum QHttp::State |
This enum is used to specify the state the client is in:
Unconnected
when the connection is closed.)Enumerator | |
---|---|
Unconnected | |
HostLookup | |
Connecting | |
Sending | |
Reading | |
Connected | |
Closing |
Definition at line 188 of file qhttp.h.
|
explicit |
Constructs a QHttp object.
The parent parameter is passed on to the QObject constructor.
Definition at line 1559 of file qhttp.cpp.
Constructs a QHttp object.
Subsequent requests are done by connecting to the server hostName on port port.
The parent parameter is passed on to the QObject constructor.
Definition at line 1574 of file qhttp.cpp.
QHttp::QHttp | ( | const QString & | hostName, |
ConnectionMode | mode, | ||
quint16 | port = 0 , |
||
QObject * | parent = 0 |
||
) |
Constructs a QHttp object.
Subsequent requests are done by connecting to the server hostName on port port using the connection mode 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.
Definition at line 1596 of file qhttp.cpp.
|
virtual |
Destroys the QHttp object.
If there is an open connection, it is closed.
Definition at line 1622 of file qhttp.cpp.
|
slot |
Aborts the current request and deletes all scheduled requests.
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
).
Definition at line 1894 of file qhttp.cpp.
Referenced by ~QHttp().
|
signal |
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.
qint64 QHttp::bytesAvailable | ( | ) | const |
void QHttp::clearPendingRequests | ( | ) |
int QHttp::close | ( | ) |
Closes the connection; this is useful if you have a keep-alive connection and want to close it.
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.
Definition at line 2420 of file qhttp.cpp.
int QHttp::closeConnection | ( | ) |
QIODevice * QHttp::currentDestinationDevice | ( | ) | const |
Returns the 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.
Definition at line 2047 of file qhttp.cpp.
int QHttp::currentId | ( | ) | const |
Returns the identifier of the HTTP request being executed or 0 if there is no request being executed (i.e.
they've all finished).
Definition at line 1979 of file qhttp.cpp.
QHttpRequestHeader QHttp::currentRequest | ( | ) | const |
Returns the request header of the HTTP request being executed.
If the request is one issued by setHost() or close(), it returns an invalid request header, i.e. QHttpRequestHeader::isValid() returns false.
Definition at line 1995 of file qhttp.cpp.
QIODevice * QHttp::currentSourceDevice | ( | ) | const |
Returns the 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.
Definition at line 2029 of file qhttp.cpp.
|
signal |
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).
|
signal |
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).
|
signal |
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.
QHttp::Error QHttp::error | ( | ) | const |
Returns the last error that occurred.
This is useful to find out what happened when receiving a requestFinished() or a done() signal with the error
argument true
.
If you start a new request, the error status is reset to NoError
.
Definition at line 3113 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_startNextRequest(), QHttpPrivate::finishedWithError(), and QHttpPrivate::setSock().
QString QHttp::errorString | ( | ) | const |
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 requestFinished() or a done() signal with the error
argument true
.
Definition at line 3125 of file qhttp.cpp.
Sends a get request for path to the server set by setHost() or as specified in the constructor.
path must be a absolute path like /index
.html or an absolute URI like http://example.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).
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.
Definition at line 2267 of file qhttp.cpp.
bool QHttp::hasPendingRequests | ( | ) | const |
int QHttp::head | ( | const QString & | path | ) |
Sends a header request for path to the server set by setHost() or as specified in the constructor.
path must be an absolute path like /index
.html or an absolute URI like http://example.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.
Definition at line 2344 of file qhttp.cpp.
|
slot |
Tells the 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.
Definition at line 3214 of file qhttp.cpp.
QHttpResponseHeader QHttp::lastResponse | ( | ) | const |
Returns the received response header of the most recently finished HTTP request.
If no response has yet been received QHttpResponseHeader::isValid() will return false.
Definition at line 2013 of file qhttp.cpp.
Sends a post request for path to the server set by setHost() or as specified in the constructor.
path must be an absolute path like /index
.html or an absolute URI like http://example.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.
Definition at line 2305 of file qhttp.cpp.
int QHttp::post | ( | const QString & | path, |
const QByteArray & | data, | ||
QIODevice * | to = 0 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.data is used as the content data of the HTTP request.
Definition at line 2318 of file qhttp.cpp.
|
signal |
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.
Referenced by QHttpPrivate::setSock().
Reads maxlen bytes from the response content into data and returns the number of bytes read.
Returns -1 if an error occurred.
Definition at line 1933 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotReadyRead(), and readAll().
QByteArray QHttp::readAll | ( | ) |
Reads all the bytes from the response content and returns them.
Definition at line 1963 of file qhttp.cpp.
|
signal |
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.
Referenced by QHttpPrivate::setSock().
int QHttp::request | ( | const QHttpRequestHeader & | header, |
QIODevice * | data = 0 , |
||
QIODevice * | to = 0 |
||
) |
Sends a request to the server set by 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.
Definition at line 2379 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest().
int QHttp::request | ( | const QHttpRequestHeader & | header, |
const QByteArray & | data, | ||
QIODevice * | to = 0 |
||
) |
|
signal |
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.
|
signal |
This signal is emitted when processing the request identified by id starts.
|
signal |
This signal is emitted when the HTTP header of a server response is available.
The header is passed in resp.
Sets the HTTP server that is used for requests to hostName on port port.
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.
Definition at line 2100 of file qhttp.cpp.
int QHttp::setHost | ( | const QString & | hostName, |
ConnectionMode | mode, | ||
quint16 | port = 0 |
||
) |
Sets the HTTP server that is used for requests to hostName on port port using the connection mode mode.
If port is 0, it will use the default port for the mode used (80 for HTTP and 443 for HTTPS).
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.
int QHttp::setProxy | ( | const QString & | host, |
int | port, | ||
const QString & | username = QString() , |
||
const QString & | password = QString() |
||
) |
Enables HTTP proxy support, using the proxy server host on port port.
username and password can be provided if the proxy server requires authentication.
Example:
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.
Definition at line 2203 of file qhttp.cpp.
int QHttp::setProxy | ( | const QNetworkProxy & | proxy | ) |
Enables HTTP proxy support using the proxy settings from proxy.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
Definition at line 2228 of file qhttp.cpp.
int QHttp::setSocket | ( | QTcpSocket * | socket | ) |
Replaces the internal 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().
Definition at line 2157 of file qhttp.cpp.
This function sets the user name userName and password password for web pages that require authentication.
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.
Definition at line 2176 of file qhttp.cpp.
Referenced by QHttpSetUserRequest::start(), and QHttpSetProxyRequest::start().
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.
Referenced by QHttpPrivate::setSock().
QHttp::State QHttp::state | ( | ) | const |
Returns the current state of the object.
When the state changes, the stateChanged() signal is emitted.
Definition at line 3100 of file qhttp.cpp.
Referenced by QHttpPrivate::_q_slotClosed(), QHttpPrivate::_q_slotConnected(), QHttpPrivate::_q_slotDoFinished(), QHttpPrivate::_q_slotError(), QHttpPrivate::_q_slotReadyRead(), QHttpPrivate::closeConn(), and QHttpPrivate::setState().
|
signal |
|
friend |
Definition at line 305 of file qhttp.h.
Referenced by close(), and closeConnection().
|
friend |
|
friend |
|
friend |
|
friend |
Definition at line 304 of file qhttp.h.
Referenced by setProxy().
|
friend |
Definition at line 302 of file qhttp.h.
Referenced by setSocket().
|
friend |