Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtNetwork.QHttp Class Reference

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

Inheritance diagram for QtNetwork.QHttp:
Collaboration diagram for QtNetwork.QHttp:

Public Types

enum  ConnectionMode { ConnectionModeHttp = 0, ConnectionModeHttps = 1 }
  More...
 
enum  Error {
  Aborted = 7, AuthenticationRequiredError = 8, ConnectionRefused = 3, HostNotFound = 2,
  InvalidResponseHeader = 5, NoError = 0, ProxyAuthenticationRequiredError = 9, UnexpectedClose = 4,
  UnknownError = 1, WrongContentLength = 6
}
  More...
 
enum  State {
  Closing = 6, Connected = 5, Connecting = 2, HostLookup = 1,
  Reading = 4, Sending = 3, Unconnected = 0
}
  More...
 

Public Member Functions

 QHttp (QObject parent=null)
 
 
 QHttp (string hostname, ushort port=80, QObject parent=null)
 
 
 QHttp (string hostname, QHttp.ConnectionMode mode, ushort port=0, QObject parent=null)
 
 
override void CreateProxy ()
 
new void Abort ()
 
 
new long BytesAvailable ()
 
 
new void ClearPendingRequests ()
 
 
new int Close ()
 
 
new int CloseConnection ()
 
 
new QIODevice CurrentDestinationDevice ()
 
 
new int CurrentId ()
 
 
new QHttpRequestHeader CurrentRequest ()
 
 
new QIODevice CurrentSourceDevice ()
 
 
new QHttp.Error error ()
 
 
new string ErrorString ()
 
 
new int Get (string path, QIODevice to=null)
 
 
new bool HasPendingRequests ()
 
 
new int Head (string path)
 
 
new void IgnoreSslErrors ()
 
 
new QHttpResponseHeader LastResponse ()
 
 
new int Post (string path, QIODevice data, QIODevice to=null)
 
 
new int Post (string path, QByteArray data, QIODevice to=null)
 
 
new long Read (Pointer< sbyte > data, long maxlen)
 
 
new QByteArray ReadAll ()
 
 
new int Request (QHttpRequestHeader header, QIODevice device=null, QIODevice to=null)
 
 
new int Request (QHttpRequestHeader header, QByteArray data, QIODevice to=null)
 
 
new int SetHost (string hostname, ushort port=80)
 
 
new int SetHost (string hostname, QHttp.ConnectionMode mode, ushort port=0)
 
 
new int SetProxy (QNetworkProxy proxy)
 
 
new int SetProxy (string host, int port, string username="", string password="")
 
 
new int SetSocket (QTcpSocket socket)
 
 
new int SetUser (string username, string password="")
 
 
new QHttp.State state ()
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QObject
 QObject (QObject parent=null)
 
 
new bool BlockSignals (bool b)
 
 
new
System.Collections.Generic.List
< QObject
Children ()
 
 
new bool Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
new void DeleteLater ()
 
 
new bool Disconnect (QObject receiver, string member=null)
 
 
new bool Disconnect (string signal=null, QObject receiver=null, string member=null)
 
 
new void DumpObjectInfo ()
 
 
new void DumpObjectTree ()
 
 
new
System.Collections.Generic.List
< QByteArray
DynamicPropertyNames ()
 
 
virtual bool OnEvent (QEvent arg1)
 
 
virtual bool EventFilter (QObject arg1, QEvent arg2)
 
 
new bool Inherits (string classname)
 
 
new void InstallEventFilter (QObject arg1)
 
 
new bool IsWidgetType ()
 
 
new void KillTimer (int id)
 
 
new object Property (string name)
 
 
new void RemoveEventFilter (QObject arg1)
 
 
new bool SetProperty (string name, object value)
 
 
new void SetUserData (uint id, QObjectUserData data)
 
new bool SignalsBlocked ()
 
 
new int StartTimer (int interval)
 
 
new QObjectUserData UserData (uint id)
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.Qt
delegate QTextStream FuncQTextStreamQTextStream (QTextStream qTextStream)
 
delegate string FuncStringQByteArray (QByteArray qByteArray)
 
delegate QByteArray FuncQByteArrayString (string @string)
 
delegate void ActionQtMsgTypeString (QtMsgType qtMsgType, string @string)
 
delegate QObject FuncQObject ()
 

Static Public Member Functions

static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QObject
static bool Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
static bool Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection)
 
 
static bool Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member)
 
 
static bool Disconnect (QObject sender, string signal, QObject receiver, string member)
 
 
static uint RegisterUserData ()
 
static string Tr (string s, string c=null)
 
 
static string Tr (string s, string c, int n)
 
 
static string TrUtf8 (string s, string c=null)
 
 
static string TrUtf8 (string s, string c, int n)
 
 
- Static Public Member Functions inherited from QtCore.Qt
static QDataStream Write (QDataStream s, object p)
 
static QDataStream Write (QDataStream arg1, QSizeF arg2)
 
static QTextStream Write (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Write (QDataStream arg1, QPoint arg2)
 
static QDataStream Write (QDataStream arg1, QLineF arg2)
 
static QDataStream Write (QDataStream arg1, QPointF arg2)
 
static QDataStream Write (QDataStream arg1, QChar arg2)
 
static QDataStream Write (QDataStream arg1, QByteArray arg2)
 
static QDataStream Write (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Write (QDataStream arg1, QRectF arg2)
 
static QDataStream Write (QDataStream arg1, QDateTime arg2)
 
static QDataStream Write (QDataStream arg1, QUrl arg2)
 
static QDataStream Write (QDataStream arg1, QTime arg2)
 
static QDataStream Write (QDataStream arg1, QLocale arg2)
 
static QDataStream Write (QDataStream arg1, QBitArray arg2)
 
static QDataStream Write (QDataStream arg1, QUuid arg2)
 
static QDataStream Write (QDataStream arg1, QLine arg2)
 
static QDataStream Write (QDataStream arg1, QDate arg2)
 
static QDataStream Write (QDataStream @out, QRegExp regExp)
 
static QDataStream Write (QDataStream arg1, QRect arg2)
 
static QDataStream Write (QDataStream arg1, QSize arg2)
 
static QDataStream Write (QDataStream s, QVariant.Type p)
 
static QDataStream Write (QDataStream arg1, string arg2)
 
static QDataStream Write (QDataStream @out, System.Collections.Generic.List< string > list)
 
static QDataStream Read (QDataStream arg1, QChar arg2)
 
static QDataStream Read (QDataStream arg1, QLocale arg2)
 
static QDataStream Read (QDataStream arg1, QRect arg2)
 
static QDataStream Read (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Read (QDataStream arg1, QDate arg2)
 
static QDataStream Read (QDataStream arg1, QUrl arg2)
 
static QDataStream Read (QDataStream arg1, QUuid arg2)
 
static QTextStream Read (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Read (QDataStream arg1, QLineF arg2)
 
static QDataStream Read (QDataStream arg1, QRectF arg2)
 
static QDataStream Read (QDataStream arg1, QPointF arg2)
 
static QDataStream Read (QDataStream arg1, QLine arg2)
 
static QDataStream Read (QDataStream arg1, QBitArray arg2)
 
static QDataStream Read (QDataStream arg1, QSize arg2)
 
static QDataStream Read (QDataStream arg1, QDateTime arg2)
 
static QDataStream Read (QDataStream arg1, QTime arg2)
 
static QDataStream Read (QDataStream arg1, QPoint arg2)
 
static QDataStream Read (QDataStream @in, QRegExp regExp)
 
static QDataStream Read (QDataStream s, object p)
 
static QDataStream Read (QDataStream arg1, QByteArray arg2)
 
static QDataStream Read (QDataStream arg1, QSizeF arg2)
 
static QDataStream Read (QDataStream arg1, string arg2)
 
static QDataStream Read (QDataStream s, QVariant.Type p)
 
static QDataStream Read (QDataStream @in, System.Collections.Generic.List< string > list)
 
static double qAcos (double v)
 
static void qAddPostRoutine (System.Action arg1)
 
static string qAppName ()
 
static double qAsin (double v)
 
static double qAtan (double v)
 
static double qAtan2 (double x, double y)
 
static void qBadAlloc ()
 
static int qCeil (double v)
 
static ushort qChecksum (string s, uint len)
 
static QByteArray qCompress (QByteArray data)
 
static QByteArray qCompress (QByteArray data, int compressionLevel=-1)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1)
 
static double qCos (double v)
 
static double qExp (double v)
 
static double qFabs (double v)
 
static double qFastCos (double x)
 
static double qFastSin (double x)
 
static string qFlagLocation (string method)
 
static int qFloor (double v)
 
static bool qFuzzyCompare (double p1, double p2)
 
static bool qFuzzyCompare (float p1, float p2)
 
static bool qFuzzyIsNull (double d)
 
static bool qFuzzyIsNull (float f)
 
static uint qHash (QBitArray key)
 
static uint qHash (QChar key)
 
static uint qHash (QStringRef key)
 
static uint qHash (QUrl url)
 
static uint qHash (QPersistentModelIndex index)
 
static uint qHash (QByteArray key)
 
static uint qHash (QModelIndex index)
 
static uint qHash (uint key)
 
static uint qHash (sbyte key)
 
static uint qHash (byte key)
 
static uint qHash (short key)
 
static uint qHash (NativeLong key)
 
static uint qHash (ushort key)
 
static uint qHash (long key)
 
static uint qHash (ulong key)
 
static uint qHash (int key)
 
static uint qHash (string key)
 
static uint qHash (NativeULong key)
 
static double qInf ()
 
static Qt.ActionQtMsgTypeString qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1)
 
static int qIntCast (float f)
 
static int qIntCast (double f)
 
static bool qIsFinite (double d)
 
static bool qIsFinite (float f)
 
static bool qIsInf (float f)
 
static bool qIsInf (double d)
 
static bool qIsNaN (float f)
 
static bool qIsNaN (double d)
 
static bool qIsNull (float f)
 
static bool qIsNull (double d)
 
static double qLn (double v)
 
static double qPow (double x, double y)
 
static double qQNaN ()
 
static void qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function)
 
static void qRemovePostRoutine (System.Action arg1)
 
static int qRound (double d)
 
static long qRound64 (double d)
 
static double qSNaN ()
 
static bool qSharedBuild ()
 
static double qSin (double v)
 
static double qSqrt (double v)
 
static bool qStringComparisonHelper (QStringRef s1, string s2)
 
static double qTan (double v)
 
static QByteArray qUncompress (QByteArray data)
 
static QByteArray qUncompress (Pointer< byte > data, int nbytes)
 
static string qVersion ()
 
static void Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size)
 
static QByteArray Qgetenv (string varName)
 
static bool Qputenv (string varName, QByteArray value)
 
static int Qrand ()
 
static void Qsrand (uint seed)
 
static int Qstrcmp (QByteArray str1, QByteArray str2)
 
static int Qstrcmp (QByteArray str1, string str2)
 
static int Qstrcmp (string str1, QByteArray str2)
 
static int Qstrcmp (string str1, string str2)
 
static Pointer< sbyte > Qstrcpy (Pointer< sbyte > dst, string src)
 
static Pointer< sbyte > Qstrdup (string arg1)
 
static int Qstricmp (string arg1, string arg2)
 
static uint Qstrlen (string str)
 
static int Qstrncmp (string str1, string str2, uint len)
 
static Pointer< sbyte > Qstrncpy (Pointer< sbyte > dst, string src, uint len)
 
static int Qstrnicmp (string arg1, string arg2, uint len)
 
static uint Qstrnlen (string str, uint maxlen)
 
static string QtTrId (string id, int n=-1)
 

Protected Member Functions

 QHttp (System.Type dummy)
 
new void OnAuthenticationRequired (string hostname, ushort port, QAuthenticator arg3)
 
 
new void OnDataReadProgress (int arg1, int arg2)
 
 
new void OnDataSendProgress (int arg1, int arg2)
 
 
new void OnDone (bool arg1)
 
 
new void OnProxyAuthenticationRequired (QNetworkProxy proxy, QAuthenticator arg2)
 
 
new void OnReadyRead (QHttpResponseHeader resp)
 
 
new void OnRequestFinished (int arg1, bool arg2)
 
 
new void OnRequestStarted (int arg1)
 
 
new void OnResponseHeaderReceived (QHttpResponseHeader resp)
 
 
new void OnSslErrors (System.Collections.Generic.List< QSslError > errors)
 
 
new void OnStateChanged (int arg1)
 
 
- Protected Member Functions inherited from QtCore.QObject
 QObject (System.Type dummy)
 
virtual void OnChildEvent (QChildEvent arg1)
 
 
virtual void ConnectNotify (string signal)
 
 
virtual void OnCustomEvent (QEvent arg1)
 
 
new void OnDestroyed (QObject arg1=null)
 
 
virtual void DisconnectNotify (string signal)
 
 
new int Receivers (string signal)
 
 
new QObject Sender ()
 
 
new int SenderSignalIndex ()
 
 
virtual void OnTimerEvent (QTimerEvent arg1)
 
 

Properties

Slot< System.Int32 > StateChanged
 
 
Slot< QHttpResponseHeaderResponseHeaderReceived
 
 
Slot< QHttpResponseHeaderReadyRead
 
 
Slot< System.Int32, System.Int32 > DataSendProgress
 
 
Slot< System.Int32, System.Int32 > DataReadProgress
 
 
Slot< System.Int32 > RequestStarted
 
 
Slot< System.Int32,
System.Boolean > 
RequestFinished
 
 
Slot< System.Boolean > Done
 
 
Slot< QNetworkProxy,
QAuthenticator
ProxyAuthenticationRequired
 
 
Slot< System.String,
System.UInt16, QAuthenticator
AuthenticationRequired
 
 
Slot
< System.Collections.Generic.List
< QSslError > > 
SslErrors
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQHttpSignals Emit [get]
 
- Properties inherited from QtCore.QObject
virtual EventHandler
< QEventArgs< QChildEvent > > 
ChildEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
CustomEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
Event
 
 
virtual EventHandler
< QEventArgs< QTimerEvent > > 
TimerEvent
 
 
Slot< QObjectDestroyedQObject
 
Slot Destroyed
 
 
new QObject Parent [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
new string ObjectName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
 
static new QMetaObject StaticQtMetaObject [get]
 
new IQObjectSignals Emit [get]
 

Additional Inherited Members

- Protected Attributes inherited from QtCore.QObject
object Q_EMIT = null
 
SmokeInvocation interceptor
 
readonly List< QEventHandler > eventFilters = new List<QEventHandler>()
 

Detailed Description

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

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

requestStarted(1)

requestFinished(1, false)

requestStarted(2)

stateChanged(Connecting)

stateChanged(Sending)

dataSendProgress(77, 77)

stateChanged(Reading)

responseHeaderReceived(responseheader)

dataReadProgress(5388, 0)

readyRead(responseheader)

dataReadProgress(18300, 0)

readyRead(responseheader)

stateChanged(Connected)

requestFinished(2, false)

done(false)

stateChanged(Closing)

stateChanged(Unconnected)

The dataSendProgress() and dataReadProgress() signals in the above example are useful if you want to show a progress bar to inform the user about the progress of the download. The second argument is the total size of data. In certain cases it is not possible to know the total amount in advance, in which case the second argument is 0. (If you connect to a QProgressBar a total of 0 results in a busy indicator.)

When the response header is read, it is reported with the responseHeaderReceived() signal.

The readyRead() signal tells you that there is data ready to be read. The amount of data can then be queried with the bytesAvailable() function and it can be read with the read() or readAll() functions.

If an error occurs during the execution of one of the commands in a sequence of commands, all the pending commands (i.e. scheduled, but not yet executed commands) are cleared and no signals are emitted for them.

For example, if you have the following sequence of requests

http->setHost("www.foo.bar"); // 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:

requestStarted(1)

requestFinished(1, false)

requestStarted(2)

stateChanged(HostLookup)

requestFinished(2, true)

done(true)

stateChanged(Unconnected)

You can then get details about the error with the error() and errorString() functions. Note that only unexpected behavior, like network failure is considered as an error. If the server response contains an error status, like a 404 response, this is reported as a normal response case. So you should always check the status code of the response header.

The functions currentId() and currentRequest() provide more information about the currently executing request.

The functions hasPendingRequests() and clearPendingRequests() allow you to query and clear the list of pending requests.

See also QFtp, QNetworkAccessManager, QNetworkRequest, QNetworkReply, HTTP Example, and Torrent Example.

Member Enumeration Documentation

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.

This enum was introduced or modified in Qt 4.3.

See also QSslSocket.

Enumerator:
ConnectionModeHttp 

The connection is a regular HTTP connection to the server

ConnectionModeHttps 

The HTTPS protocol is used and the connection is encrypted using SSL.

This enum identifies the error that occurred.

See also error().

Enumerator:
Aborted 

The request was aborted with abort().

AuthenticationRequiredError 

The web server requires authentication to complete the request.

ConnectionRefused 

The server refused the connection.

HostNotFound 

The host name lookup failed.

InvalidResponseHeader 

The server sent an invalid response header.

NoError 

No error occurred.

ProxyAuthenticationRequiredError 

QHttp is using a proxy, and the proxy server requires authentication to establish a connection.

UnexpectedClose 

The server closed the connection unexpectedly.

UnknownError 

An error other than those specified above occurred.

WrongContentLength 

The client could not read the content correctly because an error with respect to the content length occurred.

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

See also stateChanged() and state().

Enumerator:
Closing 

The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.)

Connected 

The connection to the host is open, but the client is neither sending a request, nor waiting for a response.

Connecting 

An attempt to connect to the host is in progress.

HostLookup 

A host name lookup is in progress.

Reading 

The client's request has been sent and the client is reading the server's response.

Sending 

The client is sending its request to the server.

Unconnected 

There is no connection to the host.

Constructor & Destructor Documentation

QtNetwork.QHttp.QHttp ( System.Type  dummy)
protected
QtNetwork.QHttp.QHttp ( QObject  parent = null)

Constructs a QHttp object. The parent parameter is passed on to the QObject constructor.

QtNetwork.QHttp.QHttp ( string  hostname,
ushort  port = 80,
QObject  parent = null 
)

Constructs a QHttp object. The parent parameter is passed on to the QObject constructor.

QtNetwork.QHttp.QHttp ( string  hostname,
QHttp.ConnectionMode  mode,
ushort  port = 0,
QObject  parent = null 
)

Constructs a QHttp object. The parent parameter is passed on to the QObject constructor.

Member Function Documentation

new void QtNetwork.QHttp.Abort ( )

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

new long QtNetwork.QHttp.BytesAvailable ( )

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

See also get(), post(), request(), readyRead(), read(), and readAll().

new void QtNetwork.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() and abort().

new int QtNetwork.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(), and done().

new int QtNetwork.QHttp.CloseConnection ( )

Behaves the same as close().

override void QtNetwork.QHttp.CreateProxy ( )
virtual

Reimplemented from QtCore.QObject.

new QIODevice QtNetwork.QHttp.CurrentDestinationDevice ( )

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(), and request().

new int QtNetwork.QHttp.CurrentId ( )

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

new QHttpRequestHeader QtNetwork.QHttp.CurrentRequest ( )

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

new QIODevice QtNetwork.QHttp.CurrentSourceDevice ( )

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(), and request().

new void QtNetwork.QHttp.Dispose ( )
new QHttp.Error QtNetwork.QHttp.error ( )

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.

new string QtNetwork.QHttp.ErrorString ( )

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.

new int QtNetwork.QHttp.Get ( string  path,
QIODevice  to = null 
)

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(), and done().

new bool QtNetwork.QHttp.HasPendingRequests ( )

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(), and currentRequest().

new int QtNetwork.QHttp.Head ( string  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(), and done().

new void QtNetwork.QHttp.IgnoreSslErrors ( )

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 and QSslSocket::sslErrors().

new QHttpResponseHeader QtNetwork.QHttp.LastResponse ( )

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

new void QtNetwork.QHttp.OnAuthenticationRequired ( string  hostname,
ushort  port,
QAuthenticator  arg3 
)
protected

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.

This function was introduced in Qt 4.3.

See also QAuthenticator and QNetworkProxy.

new void QtNetwork.QHttp.OnDataReadProgress ( int  arg1,
int  arg2 
)
protected

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(), and QProgressBar.

new void QtNetwork.QHttp.OnDataSendProgress ( int  arg1,
int  arg2 
)
protected

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(), and QProgressBar.

new void QtNetwork.QHttp.OnDone ( bool  arg1)
protected

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(), and errorString().

new void QtNetwork.QHttp.OnProxyAuthenticationRequired ( QNetworkProxy  proxy,
QAuthenticator  arg2 
)
protected

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.

This function was introduced in Qt 4.3.

See also QAuthenticator and QNetworkProxy.

new void QtNetwork.QHttp.OnReadyRead ( QHttpResponseHeader  resp)
protected

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(), and bytesAvailable().

new void QtNetwork.QHttp.OnRequestFinished ( int  arg1,
bool  arg2 
)
protected

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(), and errorString().

new void QtNetwork.QHttp.OnRequestStarted ( int  arg1)
protected

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

See also requestFinished() and done().

new void QtNetwork.QHttp.OnResponseHeaderReceived ( QHttpResponseHeader  resp)
protected

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(), and readyRead().

new void QtNetwork.QHttp.OnSslErrors ( System.Collections.Generic.List< QSslError errors)
protected

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.

This function was introduced in Qt 4.3.

See also QSslSocket and QSslSocket::ignoreSslErrors().

new void QtNetwork.QHttp.OnStateChanged ( int  arg1)
protected

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(), and State.

new int QtNetwork.QHttp.Post ( string  path,
QIODevice  data,
QIODevice  to = null 
)

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(), and done().

new int QtNetwork.QHttp.Post ( string  path,
QByteArray  data,
QIODevice  to = null 
)

This is an overloaded function.

data is used as the content data of the HTTP request.

new long QtNetwork.QHttp.Read ( Pointer< sbyte >  data,
long  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(), and readAll().

new QByteArray QtNetwork.QHttp.ReadAll ( )

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

See also get(), post(), request(), readyRead(), bytesAvailable(), and read().

new int QtNetwork.QHttp.Request ( QHttpRequestHeader  header,
QIODevice  device = null,
QIODevice  to = null 
)

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(), and done().

new int QtNetwork.QHttp.Request ( QHttpRequestHeader  header,
QByteArray  data,
QIODevice  to = null 
)

This is an overloaded function.

data is used as the content data of the HTTP request.

new int QtNetwork.QHttp.SetHost ( string  hostname,
ushort  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(), and done().

new int QtNetwork.QHttp.SetHost ( string  hostname,
QHttp.ConnectionMode  mode,
ushort  port = 0 
)

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(), and done().

new int QtNetwork.QHttp.SetProxy ( QNetworkProxy  proxy)

This is an overloaded function.

Enables HTTP proxy support using the proxy settings from proxy. If proxy is a transparent proxy, QHttp will call QAbstractSocket::setProxy() on the underlying socket. If the type is QNetworkProxy::HttpCachingProxy, QHttp will behave like the previous function.

Note: for compatibility with Qt 4.3, if the proxy type is QNetworkProxy::HttpProxy and the request type is unencrypted (that is, ConnectionModeHttp), QHttp will treat the proxy as a caching proxy.

new int QtNetwork.QHttp.SetProxy ( string  host,
int  port,
string  username = "",
string  password = "" 
)

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

new int QtNetwork.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() and Thread Support in Qt.

new int QtNetwork.QHttp.SetUser ( string  username,
string  password = "" 
)

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.

new QHttp.State QtNetwork.QHttp.state ( )

Returns the current state of the object. When the state changes, the stateChanged() signal is emitted.

See also State and stateChanged().

static string QtNetwork.QHttp.Tr ( string  s,
string  c = null 
)
static
static string QtNetwork.QHttp.Tr ( string  s,
string  c,
int  n 
)
static
static string QtNetwork.QHttp.TrUtf8 ( string  s,
string  c = null 
)
static
static string QtNetwork.QHttp.TrUtf8 ( string  s,
string  c,
int  n 
)
static

Property Documentation

Slot<System.String,System.UInt16,QAuthenticator> QtNetwork.QHttp.AuthenticationRequired
addremove

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.

This function was introduced in Qt 4.3.

See also QAuthenticator and QNetworkProxy.

Slot<System.Int32,System.Int32> QtNetwork.QHttp.DataReadProgress
addremove

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(), and QProgressBar.

Slot<System.Int32,System.Int32> QtNetwork.QHttp.DataSendProgress
addremove

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(), and QProgressBar.

Slot<System.Boolean> QtNetwork.QHttp.Done
addremove

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(), and errorString().

new IQHttpSignals QtNetwork.QHttp.Emit
getprotected
Slot<QNetworkProxy,QAuthenticator> QtNetwork.QHttp.ProxyAuthenticationRequired
addremove

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.

This function was introduced in Qt 4.3.

See also QAuthenticator and QNetworkProxy.

Slot<QHttpResponseHeader> QtNetwork.QHttp.ReadyRead
addremove

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(), and bytesAvailable().

Slot<System.Int32,System.Boolean> QtNetwork.QHttp.RequestFinished
addremove

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(), and errorString().

Slot<System.Int32> QtNetwork.QHttp.RequestStarted
addremove

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

See also requestFinished() and done().

Slot<QHttpResponseHeader> QtNetwork.QHttp.ResponseHeaderReceived
addremove

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(), and readyRead().

Slot<System.Collections.Generic.List<QSslError> > QtNetwork.QHttp.SslErrors
addremove

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.

This function was introduced in Qt 4.3.

See also QSslSocket and QSslSocket::ignoreSslErrors().

Slot<System.Int32> QtNetwork.QHttp.StateChanged
addremove

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(), and State.

new QMetaObject QtNetwork.QHttp.StaticMetaObject
staticget