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
qnetworkaccessmanager.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 QNETWORKACCESSMANAGER_H
5#define QNETWORKACCESSMANAGER_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtNetwork/qnetworkrequest.h>
9#include <QtCore/QString>
10#include <QtCore/QList>
11#include <QtCore/QObject>
12#ifndef QT_NO_SSL
13#include <QtNetwork/QSslConfiguration>
14#include <QtNetwork/QSslPreSharedKeyAuthenticator>
15#endif
16Q_MOC_INCLUDE(<QtNetwork/QSslError>)
17
19
20class QIODevice;
22class QAuthenticator;
23class QByteArray;
24class QNetworkCookie;
26class QNetworkReply;
27class QNetworkProxy;
29class QSslError;
30class QHstsPolicy;
31class QHttpMultiPart;
32
35class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
36{
38
39
40public:
41 enum Operation {
42 HeadOperation = 1,
48
49 UnknownOperation = 0
50 };
51
52 explicit QNetworkAccessManager(QObject *parent = nullptr);
54
55 virtual QStringList supportedSchemes() const;
56
57 void clearAccessCache();
58
59 void clearConnectionCache();
60
61#ifndef QT_NO_NETWORKPROXY
62 QNetworkProxy proxy() const;
63 void setProxy(const QNetworkProxy &proxy);
64 QNetworkProxyFactory *proxyFactory() const;
65 void setProxyFactory(QNetworkProxyFactory *factory);
66#endif
67
70
71 QNetworkCookieJar *cookieJar() const;
72 void setCookieJar(QNetworkCookieJar *cookieJar);
73
74 void setStrictTransportSecurityEnabled(bool enabled);
75 bool isStrictTransportSecurityEnabled() const;
76 void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString());
77 bool isStrictTransportSecurityStoreEnabled() const;
78 void addStrictTransportSecurityHosts(const QList<QHstsPolicy> &knownHosts);
79 QList<QHstsPolicy> strictTransportSecurityHosts() const;
80
87 QNetworkReply *post(const QNetworkRequest &request, std::nullptr_t)
88 {
89 return post(request, static_cast<QIODevice*>(nullptr));
90 }
91
94 QNetworkReply *put(const QNetworkRequest &request, std::nullptr_t)
95 {
96 return put(request, static_cast<QIODevice*>(nullptr));
97 }
98
102
103#if QT_CONFIG(http) || defined(Q_OS_WASM)
107#endif
108
109#ifndef QT_NO_SSL
110 void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
112 void connectToHostEncrypted(const QString &hostName, quint16 port,
113 const QSslConfiguration &sslConfiguration,
114 const QString &peerName);
115#endif
116 void connectToHost(const QString &hostName, quint16 port = 80);
117
118 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
119 QNetworkRequest::RedirectPolicy redirectPolicy() const;
120
121 bool autoDeleteReplies() const;
122 void setAutoDeleteReplies(bool autoDelete);
123
124 QT_NETWORK_INLINE_SINCE(6, 8)
125 int transferTimeout() const;
126 QT_NETWORK_INLINE_SINCE(6, 8)
127 void setTransferTimeout(int timeout);
128
129 std::chrono::milliseconds transferTimeoutAsDuration() const;
130 void setTransferTimeout(std::chrono::milliseconds duration =
131 QNetworkRequest::DefaultTransferTimeout);
132
134#ifndef QT_NO_NETWORKPROXY
136#endif
139#ifndef QT_NO_SSL
141 void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
143#endif
144
145protected:
146 virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
147 QIODevice *outgoingData = nullptr);
148
149protected Q_SLOTS:
150 QStringList supportedSchemesImplementation() const;
151
152private:
157
158#ifdef Q_OS_WASM
159 friend class QNetworkReplyWasmImpl;
160#endif
161 Q_DECLARE_PRIVATE(QNetworkAccessManager)
162 Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
163#ifndef QT_NO_SSL
164 Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
165#endif
166};
167
168#if QT_NETWORK_INLINE_IMPL_SINCE(6, 8)
170{
171 return int(transferTimeoutAsDuration().count());
172}
173
175{
176 setTransferTimeout(std::chrono::milliseconds(timeout));
177}
178#endif // INLINE_SINCE 6.8
179
181
182#endif
The QAbstractNetworkCache class provides the interface for cache implementations.
The QAuthenticator class provides an authentication object.
\inmodule QtCore
Definition qbytearray.h:57
The QHstsPolicy class specifies that a host supports HTTP Strict Transport Security policy (HSTS).
Definition qhstspolicy.h:19
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QNetworkAccessManager class allows the application to send network requests and receive replies.
QNetworkReply * put(const QNetworkRequest &request, std::nullptr_t)
void finished(QNetworkReply *reply)
This signal is emitted whenever a pending network reply is finished.
QNetworkReply * post(const QNetworkRequest &request, std::nullptr_t)
void setTransferTimeout(int timeout)
void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator)
void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
This signal is emitted whenever a final server requests authentication before it delivers the request...
std::chrono::milliseconds transferTimeoutAsDuration() const
void encrypted(QNetworkReply *reply)
int transferTimeout() const
void sslErrors(QNetworkReply *reply, const QList< QSslError > &errors)
This signal is emitted if the SSL/TLS session encountered errors during the set up,...
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
This signal is emitted whenever a proxy requests authentication and QNetworkAccessManager cannot find...
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
The QNetworkCookie class holds one network cookie.
The QNetworkProxyFactory class provides fine-grained proxy selection.
The QNetworkProxy class provides a network layer proxy.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
The QSslError class provides an SSL error.
Definition qsslerror.h:21
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
static QDBusError::ErrorType get(const char *name)
EGLOutputPortEXT port
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
#define Q_OBJECT
#define Q_SLOTS
#define Q_MOC_INCLUDE(...)
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
unsigned short quint16
Definition qtypes.h:48
sock connectToHost(url.host(), url.port(80))
QItemEditorFactory * factory
QSizePolicy policy
QHttpMultiPart * multiPart
[0]
QNetworkRequest request(url)
QNetworkReply * reply
manager setCache(diskCache)
manager deleteResource(request, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[7]
manager head(request, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[6]
manager post(request, myJson, this, [this](QRestReply &reply) { if(!reply.isSuccess()) { } if(std::optional json=reply.readJson()) { } })
manager sendCustomRequest(request, "MYMETHOD", myData, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[8]
manager put(request, myData, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[5]
QNetworkProxy proxy
[0]
serverSocket setProxy(QNetworkProxy::NoProxy)
[0]
socket connectToHostEncrypted("imap.example.com", 993)