Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Friends | List of all members
QHttp Class Reference

The QHttp class provides an implementation of the HTTP protocol. More...

#include <qhttp.h>

Inheritance diagram for QHttp:
QObject

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...
 
QIODevicecurrentDestinationDevice () 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...
 
QIODevicecurrentSourceDevice () 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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (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...
 
QObjectsender () 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< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QHttp class provides an implementation of the HTTP protocol.

Note
This class or function is reentrant.
Attention
Module: QtNetwork

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):

QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/index.html"));
header.setValue("Host", "qt.nokia.com");
http->setHost("qt.nokia.com");
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("qt.nokia.com"); // id == 1
http->get(QUrl::toPercentEncoding("/index.html")); // id == 2

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

http->setHost("www.foo.bar"); // id == 1
http->get("/index.html"); // id == 2
http->post("register.html", data); // id == 3

and the get() request fails because the host lookup fails, then the post() request is never executed and the signals would look like this:

requestFinished(1, false)
requestFinished(2, true)
done(true)

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.

See also
QFtp, QNetworkAccessManager, QNetworkRequest, QNetworkReply, {HTTP Example}, {Torrent Example}

Definition at line 173 of file qhttp.h.

Enumerations

◆ ConnectionMode

This enum is used to specify the mode of connection to use:

  • ConnectionModeHttp The connection is a regular HTTP connection to the server
  • ConnectionModeHttps The HTTPS protocol is used and the connection is encrypted using SSL.
Since
4.3

When using the HTTPS mode, care should be taken to connect to the sslErrors signal, and handle possible SSL errors.

See also
QSslSocket
Enumerator
ConnectionModeHttp 
ConnectionModeHttps 

Definition at line 178 of file qhttp.h.

◆ Error

This enum identifies the error that occurred.

  • NoError No error occurred.
  • HostNotFound The host name lookup failed.
  • ConnectionRefused The server refused the connection.
  • UnexpectedClose The server closed the connection unexpectedly.
  • InvalidResponseHeader The server sent an invalid response header.
  • WrongContentLength The client could not read the content correctly because an error with respect to the content length occurred.
  • Aborted The request was aborted with abort().
  • ProxyAuthenticationRequiredError QHttp is using a proxy, and the proxy server requires authentication to establish a connection.
  • AuthenticationRequiredError The web server requires authentication to complete the request.
  • UnknownError An error other than those specified above occurred.
See also
error()
Enumerator
NoError 
UnknownError 
HostNotFound 
ConnectionRefused 
UnexpectedClose 
InvalidResponseHeader 
WrongContentLength 
Aborted 
AuthenticationRequiredError 
ProxyAuthenticationRequiredError 

Definition at line 197 of file qhttp.h.

◆ State

This enum is used to specify the state the client is in:

  • Unconnected There is no connection to the host.
  • HostLookup A host name lookup is in progress.
  • Connecting An attempt to connect to the host is in progress.
  • Sending The client is sending its request to the server.
  • Reading The client's request has been sent and the client is reading the server's response.
  • Connected The connection to the host is open, but the client is neither sending a request, nor waiting for a response.
  • Closing The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.)
See also
stateChanged() state()
Enumerator
Unconnected 
HostLookup 
Connecting 
Sending 
Reading 
Connected 
Closing 

Definition at line 188 of file qhttp.h.

Constructors and Destructors

◆ QHttp() [1/3]

QHttp::QHttp ( QObject parent = 0)
explicit

Constructs a QHttp object.

The parent parameter is passed on to the QObject constructor.

Definition at line 1559 of file qhttp.cpp.

1560  : QObject(*new QHttpPrivate, parent)
1561 {
1562  Q_D(QHttp);
1563  d->init();
1564 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QHttp() [2/3]

QHttp::QHttp ( const QString hostName,
quint16  port = 80,
QObject parent = 0 
)

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.

See also
setHost()

Definition at line 1574 of file qhttp.cpp.

1575  : QObject(*new QHttpPrivate, parent)
1576 {
1577  Q_D(QHttp);
1578  d->init();
1579 
1580  d->hostName = hostName;
1581  d->port = port;
1582 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QHttp() [3/3]

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.

See also
setHost()

Definition at line 1596 of file qhttp.cpp.

1597  : QObject(*new QHttpPrivate, parent)
1598 {
1599  Q_D(QHttp);
1600  d->init();
1601 
1602  d->hostName = hostName;
1603  if (port == 0)
1604  port = (mode == ConnectionModeHttp) ? 80 : 443;
1605  d->port = port;
1606  d->mode = mode;
1607 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QHttp()

QHttp::~QHttp ( )
virtual

Destroys the QHttp object.

If there is an open connection, it is closed.

Definition at line 1622 of file qhttp.cpp.

1623 {
1624  abort();
1625 }
void abort()
Aborts the current request and deletes all scheduled requests.
Definition: qhttp.cpp:1894

Functions

◆ abort

void QHttp::abort ( )
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).

See also
clearPendingRequests()

Definition at line 1894 of file qhttp.cpp.

Referenced by ~QHttp().

1895 {
1896  Q_D(QHttp);
1897  if (d->pending.isEmpty())
1898  return;
1899 
1900  d->finishedWithError(tr("Request aborted"), Aborted);
1902  if (d->socket)
1903  d->socket->abort();
1904  d->closeConn();
1905 }
double d
Definition: qnumeric_p.h:62
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
void clearPendingRequests()
Deletes all pending requests from the list of scheduled requests.
Definition: qhttp.cpp:2077

◆ authenticationRequired

void QHttp::authenticationRequired ( const QString hostname,
quint16  port,
QAuthenticator authenticator 
)
signal
Since
4.3

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.
See also
QAuthenticator, QNetworkProxy

◆ bytesAvailable()

qint64 QHttp::bytesAvailable ( ) const

Returns the number of bytes that can be read from the response content at the moment.

See also
get() post() request() readyRead() read() readAll()

Definition at line 1913 of file qhttp.cpp.

Referenced by readAll().

1914 {
1915  Q_D(const QHttp);
1916 #if defined(QHTTP_DEBUG)
1917  qDebug("QHttp::bytesAvailable(): %d bytes", (int)d->rba.size());
1918 #endif
1919  return qint64(d->rba.size());
1920 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
__int64 qint64
Definition: qglobal.h:942
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ clearPendingRequests()

void QHttp::clearPendingRequests ( )

Deletes all pending requests from the list of scheduled requests.

This does not affect the request that is being executed. If you want to stop this as well, use abort().

See also
hasPendingRequests() abort()

Definition at line 2077 of file qhttp.cpp.

Referenced by abort().

2078 {
2079  Q_D(QHttp);
2080  // delete all entires except the first one
2081  while (d->pending.count() > 1)
2082  delete d->pending.takeLast();
2083 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ close()

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.

See also
stateChanged() abort() requestStarted() requestFinished() done()

Definition at line 2420 of file qhttp.cpp.

2421 {
2422  Q_D(QHttp);
2423  return d->addRequest(new QHttpCloseRequest());
2424 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
friend class QHttpCloseRequest
Definition: qhttp.h:305
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ closeConnection()

int QHttp::closeConnection ( )

Behaves the same as close().

Definition at line 2434 of file qhttp.cpp.

2435 {
2436  Q_D(QHttp);
2437  return d->addRequest(new QHttpCloseRequest());
2438 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
friend class QHttpCloseRequest
Definition: qhttp.h:305
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ currentDestinationDevice()

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.

See also
currentSourceDevice() get() post() request()

Definition at line 2047 of file qhttp.cpp.

2048 {
2049  Q_D(const QHttp);
2050  if (d->pending.isEmpty())
2051  return 0;
2052  return d->pending.first()->destinationDevice();
2053 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ currentId()

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).

See also
currentRequest()

Definition at line 1979 of file qhttp.cpp.

1980 {
1981  Q_D(const QHttp);
1982  if (d->pending.isEmpty())
1983  return 0;
1984  return d->pending.first()->id;
1985 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ currentRequest()

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.

See also
currentId()

Definition at line 1995 of file qhttp.cpp.

1996 {
1997  Q_D(const QHttp);
1998  if (!d->pending.isEmpty()) {
1999  QHttpRequest *r = d->pending.first();
2000  if (r->hasRequestHeader())
2001  return r->requestHeader();
2002  }
2003  return QHttpRequestHeader();
2004 }
double d
Definition: qnumeric_p.h:62
virtual QHttpRequestHeader requestHeader()
Definition: qhttp.cpp:190
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
virtual bool hasRequestHeader()
Definition: qhttp.cpp:185

◆ currentSourceDevice()

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.

See also
currentDestinationDevice() post() request()

Definition at line 2029 of file qhttp.cpp.

2030 {
2031  Q_D(const QHttp);
2032  if (d->pending.isEmpty())
2033  return 0;
2034  return d->pending.first()->sourceDevice();
2035 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ dataReadProgress

void QHttp::dataReadProgress ( int  done,
int  total 
)
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).

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.
See also
dataSendProgress() get() post() request() QProgressBar

◆ dataSendProgress

void QHttp::dataSendProgress ( int  done,
int  total 
)
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).

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.
See also
dataReadProgress(), post(), request(), QProgressBar

◆ done

void QHttp::done ( bool  error)
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.

See also
requestFinished() error() errorString()

◆ error()

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().

3114 {
3115  Q_D(const QHttp);
3116  return d->error;
3117 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ errorString()

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.

3126 {
3127  Q_D(const QHttp);
3128  return d->errorString;
3129 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ get()

int QHttp::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.

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).

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.

See also
setHost(), post(), head(), request(), requestStarted(), requestFinished(), done()

Definition at line 2267 of file qhttp.cpp.

2268 {
2269  Q_D(QHttp);
2270  QHttpRequestHeader header(QLatin1String("GET"), path);
2271  header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
2272  return d->addRequest(new QHttpPGHRequest(header, (QIODevice *) 0, to));
2273 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpPGHRequest
Definition: qhttp.h:306
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ hasPendingRequests()

bool QHttp::hasPendingRequests ( ) const

Returns true if there are any requests scheduled that have not yet been executed; otherwise returns false.

The request that is being executed is not considered as a scheduled request.

See also
clearPendingRequests() currentId() currentRequest()

Definition at line 2064 of file qhttp.cpp.

2065 {
2066  Q_D(const QHttp);
2067  return d->pending.count() > 1;
2068 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ head()

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.

See also
setHost() get() post() request() requestStarted() requestFinished() done()

Definition at line 2344 of file qhttp.cpp.

2345 {
2346  Q_D(QHttp);
2347  QHttpRequestHeader header(QLatin1String("HEAD"), path);
2348  header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
2349  return d->addRequest(new QHttpPGHRequest(header, (QIODevice*)0, 0));
2350 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpPGHRequest
Definition: qhttp.h:306
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ ignoreSslErrors

void QHttp::ignoreSslErrors ( )
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.

See also
QSslSocket QSslSocket::sslErrors()

Definition at line 3214 of file qhttp.cpp.

3215 {
3216  Q_D(QHttp);
3217  QSslSocket *sslSocket = qobject_cast<QSslSocket *>(d->socket);
3218  if (sslSocket)
3219  sslSocket->ignoreSslErrors();
3220 }
double d
Definition: qnumeric_p.h:62
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition: qsslsocket.h:67
void ignoreSslErrors(const QList< QSslError > &errors)
This method tells QSslSocket to ignore only the errors given in errors.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ lastResponse()

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.

See also
currentRequest()

Definition at line 2013 of file qhttp.cpp.

2014 {
2015  Q_D(const QHttp);
2016  return d->response;
2017 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ post() [1/2]

int QHttp::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.

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.

See also
setHost() get() head() request() requestStarted() requestFinished() done()

Definition at line 2305 of file qhttp.cpp.

2306 {
2307  Q_D(QHttp);
2308  QHttpRequestHeader header(QLatin1String("POST"), path);
2309  header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
2310  return d->addRequest(new QHttpPGHRequest(header, data, to));
2311 }
double d
Definition: qnumeric_p.h:62
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpPGHRequest
Definition: qhttp.h:306
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ post() [2/2]

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.

2319 {
2320  Q_D(QHttp);
2321  QHttpRequestHeader header(QLatin1String("POST"), path);
2322  header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
2323  return d->addRequest(new QHttpPGHRequest(header, new QByteArray(data), to));
2324 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpPGHRequest
Definition: qhttp.h:306
The QHttpRequestHeader class contains request header information for HTTP.
Definition: qhttp.h:147

◆ proxyAuthenticationRequired

void QHttp::proxyAuthenticationRequired ( const QNetworkProxy proxy,
QAuthenticator authenticator 
)
signal
Since
4.3

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.
See also
QAuthenticator, QNetworkProxy

Referenced by QHttpPrivate::setSock().

◆ read()

qint64 QHttp::read ( char *  data,
qint64  maxlen 
)

Reads maxlen bytes from the response content into data and returns the number of bytes read.

Returns -1 if an error occurred.

See also
get() post() request() readyRead() bytesAvailable() readAll()

Definition at line 1933 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotReadyRead(), and readAll().

1934 {
1935  Q_D(QHttp);
1936  if (data == 0 && maxlen != 0) {
1937  qWarning("QHttp::read: Null pointer error");
1938  return -1;
1939  }
1940  if (maxlen >= d->rba.size())
1941  maxlen = d->rba.size();
1942  int readSoFar = 0;
1943  while (!d->rba.isEmpty() && readSoFar < maxlen) {
1944  int nextBlockSize = d->rba.nextDataBlockSize();
1945  int bytesToRead = qMin<qint64>(maxlen - readSoFar, nextBlockSize);
1946  memcpy(data + readSoFar, d->rba.readPointer(), bytesToRead);
1947  d->rba.free(bytesToRead);
1948  readSoFar += bytesToRead;
1949  }
1950 
1951  d->bytesDone += maxlen;
1952 #if defined(QHTTP_DEBUG)
1953  qDebug("QHttp::read(): read %lld bytes (%lld bytes done)", maxlen, d->bytesDone);
1954 #endif
1955  return maxlen;
1956 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ readAll()

QByteArray QHttp::readAll ( )

Reads all the bytes from the response content and returns them.

See also
get() post() request() readyRead() bytesAvailable() read()

Definition at line 1963 of file qhttp.cpp.

1964 {
1965  qint64 avail = bytesAvailable();
1966  QByteArray tmp;
1967  tmp.resize(int(avail));
1968  qint64 got = read(tmp.data(), int(avail));
1969  tmp.resize(got);
1970  return tmp;
1971 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
qint64 bytesAvailable() const
Returns the number of bytes that can be read from the response content at the moment.
Definition: qhttp.cpp:1913
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
__int64 qint64
Definition: qglobal.h:942
void resize(int size)
Sets the size of the byte array to size bytes.
qint64 read(char *data, qint64 maxlen)
Reads maxlen bytes from the response content into data and returns the number of bytes read...
Definition: qhttp.cpp:1933

◆ readyRead

void QHttp::readyRead ( const QHttpResponseHeader resp)
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.

See also
get() post() request() readAll() read() bytesAvailable()

Referenced by QHttpPrivate::setSock().

◆ request() [1/2]

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.

See also
setHost() get() post() head() requestStarted() requestFinished() done()

Definition at line 2379 of file qhttp.cpp.

Referenced by QHttpPrivate::_q_slotSendRequest().

2380 {
2381  Q_D(QHttp);
2382  return d->addRequest(new QHttpNormalRequest(header, data, to));
2383 }
double d
Definition: qnumeric_p.h:62
friend class QHttpNormalRequest
Definition: qhttp.h:300
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ request() [2/2]

int QHttp::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.

Definition at line 2390 of file qhttp.cpp.

2391 {
2392  Q_D(QHttp);
2393  return d->addRequest(new QHttpNormalRequest(header, new QByteArray(data), to));
2394 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
friend class QHttpNormalRequest
Definition: qhttp.h:300
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ requestFinished

void QHttp::requestFinished ( int  id,
bool  error 
)
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.

See also
requestStarted() done() error() errorString()

◆ requestStarted

void QHttp::requestStarted ( int  id)
signal

This signal is emitted when processing the request identified by id starts.

See also
requestFinished() done()

◆ responseHeaderReceived

void QHttp::responseHeaderReceived ( const QHttpResponseHeader resp)
signal

This signal is emitted when the HTTP header of a server response is available.

The header is passed in resp.

See also
get() post() head() request() readyRead()

◆ setHost() [1/2]

int QHttp::setHost ( const QString hostName,
quint16  port = 80 
)

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.

See also
get() post() head() request() requestStarted() requestFinished() done()

Definition at line 2100 of file qhttp.cpp.

2101 {
2102  Q_D(QHttp);
2103  return d->addRequest(new QHttpSetHostRequest(hostName, port, ConnectionModeHttp));
2104 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
friend class QHttpSetHostRequest
Definition: qhttp.h:301
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ setHost() [2/2]

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.

See also
get() post() head() request() requestStarted() requestFinished() done()

Definition at line 2124 of file qhttp.cpp.

2125 {
2126 #ifdef QT_NO_OPENSSL
2127  if (mode == ConnectionModeHttps)
2128  qWarning("QHttp::setHost: HTTPS connection requested but SSL support not compiled in");
2129 #endif
2130  Q_D(QHttp);
2131  if (port == 0)
2132  port = (mode == ConnectionModeHttp) ? 80 : 443;
2133  return d->addRequest(new QHttpSetHostRequest(hostName, port, mode));
2134 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
friend class QHttpSetHostRequest
Definition: qhttp.h:301
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ setProxy() [1/2]

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:

void Ticker::getTicks()
{
http = new QHttp(this);
connect(http, SIGNAL(done(bool)), this, SLOT(showPage()));
http->setProxy("proxy.example.com", 3128);
http->setHost("ticker.example.com");
http->get("/ticks.asp");
}
void Ticker::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.

Note
setProxy() has to be called before setHost() for it to take effect. If setProxy() is called after setHost(), then it will not apply until after setHost() is called again.
See also
QFtp::setProxy()

Definition at line 2203 of file qhttp.cpp.

2205 {
2206  Q_D(QHttp);
2207  QNetworkProxy proxy(QNetworkProxy::HttpProxy, host, port, username, password);
2208  return d->addRequest(new QHttpSetProxyRequest(proxy));
2209 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QNetworkProxy class provides a network layer proxy.
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpSetProxyRequest
Definition: qhttp.h:304

◆ setProxy() [2/2]

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.

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.

Definition at line 2228 of file qhttp.cpp.

2229 {
2230  Q_D(QHttp);
2231  return d->addRequest(new QHttpSetProxyRequest(proxy));
2232 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173
friend class QHttpSetProxyRequest
Definition: qhttp.h:304

◆ setSocket()

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().

See also
QObject::moveToThread(), {Thread Support in Qt}

Definition at line 2157 of file qhttp.cpp.

2158 {
2159  Q_D(QHttp);
2160  return d->addRequest(new QHttpSetSocketRequest(socket));
2161 }
double d
Definition: qnumeric_p.h:62
friend class QHttpSetSocketRequest
Definition: qhttp.h:302
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ setUser()

int QHttp::setUser ( const QString userName,
const QString password = QString() 
)

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().

2177 {
2178  Q_D(QHttp);
2179  return d->addRequest(new QHttpSetUserRequest(userName, password));
2180 }
double d
Definition: qnumeric_p.h:62
friend class QHttpSetUserRequest
Definition: qhttp.h:303
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ sslErrors

void QHttp::sslErrors ( const QList< QSslError > &  errors)
signal

Forwards the sslErrors signal from the QSslSocket used in QHttp.

Since
4.3

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.

See also
QSslSocket QSslSocket::ignoreSslErrors()

Referenced by QHttpPrivate::setSock().

◆ state()

QHttp::State QHttp::state ( ) const

Returns the current state of the object.

When the state changes, the stateChanged() signal is emitted.

See also
State stateChanged()

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().

3101 {
3102  Q_D(const QHttp);
3103  return d->state;
3104 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QHttp class provides an implementation of the HTTP protocol.
Definition: qhttp.h:173

◆ stateChanged

void QHttp::stateChanged ( int  state)
signal

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.

See also
get() post() head() request() close() state() State

Friends and Related Functions

◆ QHttpCloseRequest

friend class QHttpCloseRequest
friend

Definition at line 305 of file qhttp.h.

Referenced by close(), and closeConnection().

◆ QHttpNormalRequest

friend class QHttpNormalRequest
friend

Definition at line 300 of file qhttp.h.

Referenced by request().

◆ QHttpPGHRequest

friend class QHttpPGHRequest
friend

Definition at line 306 of file qhttp.h.

Referenced by get(), head(), and post().

◆ QHttpSetHostRequest

friend class QHttpSetHostRequest
friend

Definition at line 301 of file qhttp.h.

Referenced by setHost().

◆ QHttpSetProxyRequest

friend class QHttpSetProxyRequest
friend

Definition at line 304 of file qhttp.h.

Referenced by setProxy().

◆ QHttpSetSocketRequest

Definition at line 302 of file qhttp.h.

Referenced by setSocket().

◆ QHttpSetUserRequest

friend class QHttpSetUserRequest
friend

Definition at line 303 of file qhttp.h.

Referenced by setUser().


The documentation for this class was generated from the following files: