Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qnetworkreply.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QNETWORKREPLY_H
5#define QNETWORKREPLY_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/QIODevice>
9#include <QtCore/QString>
10#include <QtCore/QVariant>
11
12#include <QtNetwork/QNetworkRequest>
13#include <QtNetwork/QNetworkAccessManager>
14
16
17
18class QUrl;
19class QVariant;
20class QAuthenticator;
22class QSslError;
24
26class Q_NETWORK_EXPORT QNetworkReply: public QIODevice
27{
29public:
32
33 // network layer errors [relating to the destination server] (1-99):
34 ConnectionRefusedError = 1,
45 UnknownNetworkError = 99,
46
47 // proxy errors (101-199):
48 ProxyConnectionRefusedError = 101,
53 UnknownProxyError = 199,
54
55 // content errors (201-299):
56 ContentAccessDenied = 201,
63 UnknownContentError = 299,
64
65 // protocol errors
66 ProtocolUnknownError = 301,
68 ProtocolFailure = 399,
69
70 // Server side errors (401-499)
71 InternalServerError = 401,
74 UnknownServerError = 499
75 };
76 Q_ENUM(NetworkError)
77
79
80 // reimplemented from QIODevice
81 virtual void close() override;
82 virtual bool isSequential() const override;
83
84 // like QAbstractSocket:
85 qint64 readBufferSize() const;
86 virtual void setReadBufferSize(qint64 size);
87
89 QNetworkAccessManager::Operation operation() const;
91 NetworkError error() const;
92 bool isFinished() const;
93 bool isRunning() const;
94 QUrl url() const;
95
96 // "cooked" headers
98
99 // raw headers:
100#if QT_NETWORK_REMOVED_SINCE(6, 7)
101 bool hasRawHeader(const QByteArray &headerName) const;
102#endif
103 bool hasRawHeader(QAnyStringView headerName) const;
104 QList<QByteArray> rawHeaderList() const;
105#if QT_NETWORK_REMOVED_SINCE(6, 7)
106 QByteArray rawHeader(const QByteArray &headerName) const;
107#endif
108 QByteArray rawHeader(QAnyStringView headerName) const;
109
110 typedef QPair<QByteArray, QByteArray> RawHeaderPair;
111 const QList<RawHeaderPair>& rawHeaderPairs() const;
112 QHttpHeaders headers() const;
113
114 // attributes
116
117#if QT_CONFIG(ssl)
118 QSslConfiguration sslConfiguration() const;
119 void setSslConfiguration(const QSslConfiguration &configuration);
120 void ignoreSslErrors(const QList<QSslError> &errors);
121#endif
122
123public Q_SLOTS:
124 virtual void abort() = 0;
125 virtual void ignoreSslErrors();
126
131 void finished();
133#if QT_CONFIG(ssl)
134 void encrypted();
135 void sslErrors(const QList<QSslError> &errors);
136 void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
137#endif
138 void redirected(const QUrl &url);
140
141 void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
142 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
143
144protected:
145 explicit QNetworkReply(QObject *parent = nullptr);
147 virtual qint64 writeData(const char *data, qint64 len) override;
148
149 void setOperation(QNetworkAccessManager::Operation operation);
150 void setRequest(const QNetworkRequest &request);
151 void setError(NetworkError errorCode, const QString &errorString);
152 void setFinished(bool);
153 void setUrl(const QUrl &url);
155 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
156 void setHeaders(const QHttpHeaders &newHeaders);
157 void setHeaders(QHttpHeaders &&newHeaders);
158 void setWellKnownHeader(QHttpHeaders::WellKnownHeader name, const QByteArray &value);
160
161#if QT_CONFIG(ssl)
162 virtual void sslConfigurationImplementation(QSslConfiguration &) const;
163 virtual void setSslConfigurationImplementation(const QSslConfiguration &);
164 virtual void ignoreSslErrorsImplementation(const QList<QSslError> &);
165#endif
166
167private:
168 Q_DECLARE_PRIVATE(QNetworkReply)
169};
170
172
174 QNetworkReply__NetworkError, Q_NETWORK_EXPORT)
175
176#endif
\inmodule QtCore
The QAuthenticator class provides an authentication object.
\inmodule QtCore
Definition qbytearray.h:57
WellKnownHeader
List of well known headers as per \l {https://www.iana.org/assignments/http-fields}{IANA registry}.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QNetworkAccessManager class allows the application to send network requests and receive replies.
Operation
Indicates the operation this reply is processing.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void socketStartedConnecting()
void redirectAllowed()
void errorOccurred(QNetworkReply::NetworkError)
void requestSent()
void metaDataChanged()
\omit FIXME: Update name? \endomit
void uploadProgress(qint64 bytesSent, qint64 bytesTotal)
This signal is emitted to indicate the progress of the upload part of this network request,...
void redirected(const QUrl &url)
QPair< QByteArray, QByteArray > RawHeaderPair
RawHeaderPair is a QPair<QByteArray, QByteArray> where the first QByteArray is the header name and th...
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
This signal is emitted to indicate the progress of the download part of this network request,...
virtual void abort()=0
Aborts the operation immediately and close down any network connections still open.
NetworkError
Indicates all possible error conditions found during the processing of the request.
@ ContentOperationNotPermittedError
@ OperationNotImplementedError
@ TemporaryNetworkFailureError
@ BackgroundRequestNotAllowedError
@ ProtocolInvalidOperationError
@ ProxyAuthenticationRequiredError
@ AuthenticationRequiredError
void finished()
This signal is emitted when the reply has finished processing.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
KnownHeaders
List of known header types that QNetworkRequest parses.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
The QSslError class provides an SSL error.
Definition qsslerror.h:21
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
Definition qmetatype.h:1376
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLenum GLsizei len
static void setError(QJsonObject *response, const QString &msg)
request setUrl(QUrl("http://qt-project.org"))
static bool isRunning()
Definition main.cpp:452
@ NoError
Definition main.cpp:34
#define Q_ENUM(x)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]
void writeData(const QByteArray &data)
app setAttribute(Qt::AA_DontShowIconsInMenus)
QNetworkAccessManager manager
QNetworkRequest request(url)
textPart setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""))
imagePart setRawHeader("Content-ID", "my@content.id")
reply ignoreSslErrors(expectedSslErrors)
sslSocket setSslConfiguration(config)