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 nptr);
90 QNetworkReply *put(const QNetworkRequest &request, std::nullptr_t nptr);
94
95#if QT_CONFIG(http) || defined(Q_OS_WASM)
99#endif
100
101#ifndef QT_NO_SSL
102 void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
104 void connectToHostEncrypted(const QString &hostName, quint16 port,
105 const QSslConfiguration &sslConfiguration,
106 const QString &peerName);
107#endif
108 void connectToHost(const QString &hostName, quint16 port = 80);
109
110 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
111 QNetworkRequest::RedirectPolicy redirectPolicy() const;
112
113 bool autoDeleteReplies() const;
114 void setAutoDeleteReplies(bool autoDelete);
115
116 QT_NETWORK_INLINE_SINCE(6, 8)
117 int transferTimeout() const;
118 QT_NETWORK_INLINE_SINCE(6, 8)
119 void setTransferTimeout(int timeout);
120
121 std::chrono::milliseconds transferTimeoutAsDuration() const;
122 void setTransferTimeout(std::chrono::milliseconds duration =
123 QNetworkRequest::DefaultTransferTimeout);
124
126#ifndef QT_NO_NETWORKPROXY
128#endif
131#ifndef QT_NO_SSL
133 void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
135#endif
136
137protected:
138 virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
139 QIODevice *outgoingData = nullptr);
140
141protected Q_SLOTS:
142 QStringList supportedSchemesImplementation() const;
143
144private:
149
150#ifdef Q_OS_WASM
151 friend class QNetworkReplyWasmImpl;
152#endif
153 Q_DECLARE_PRIVATE(QNetworkAccessManager)
154 Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
155#ifndef QT_NO_SSL
156 Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
157#endif
158};
159
160#if QT_NETWORK_INLINE_IMPL_SINCE(6, 8)
162{
163 return int(transferTimeoutAsDuration().count());
164}
165
167{
168 setTransferTimeout(std::chrono::milliseconds(timeout));
169}
170#endif // INLINE_SINCE 6.8
171
173
174#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.
void finished(QNetworkReply *reply)
This signal is emitted whenever a pending network reply is finished.
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)