QtBase  v6.3.1
qnetworkaccessmanager.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QNETWORKACCESSMANAGER_H
41 #define QNETWORKACCESSMANAGER_H
42 
43 #include <QtNetwork/qtnetworkglobal.h>
44 #include <QtNetwork/qnetworkrequest.h>
45 #include <QtCore/QString>
46 #include <QtCore/QList>
47 #include <QtCore/QObject>
48 #ifndef QT_NO_SSL
49 #include <QtNetwork/QSslConfiguration>
50 #include <QtNetwork/QSslPreSharedKeyAuthenticator>
51 #endif
52 Q_MOC_INCLUDE(<QtNetwork/QSslError>)
53 
55 
56 class QIODevice;
58 class QAuthenticator;
59 class QByteArray;
60 class QNetworkCookie;
61 class QNetworkCookieJar;
62 class QNetworkReply;
63 class QNetworkProxy;
65 class QSslError;
66 class QHstsPolicy;
67 class QHttpMultiPart;
68 
71 class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
72 {
73  Q_OBJECT
74 
75 
76 public:
77  enum Operation {
78  HeadOperation = 1,
84 
85  UnknownOperation = 0
86  };
87 
88  explicit QNetworkAccessManager(QObject *parent = nullptr);
90 
91  virtual QStringList supportedSchemes() const;
92 
93  void clearAccessCache();
94 
95  void clearConnectionCache();
96 
97 #ifndef QT_NO_NETWORKPROXY
98  QNetworkProxy proxy() const;
99  void setProxy(const QNetworkProxy &proxy);
100  QNetworkProxyFactory *proxyFactory() const;
101  void setProxyFactory(QNetworkProxyFactory *factory);
102 #endif
103 
104  QAbstractNetworkCache *cache() const;
106 
107  QNetworkCookieJar *cookieJar() const;
108  void setCookieJar(QNetworkCookieJar *cookieJar);
109 
110  void setStrictTransportSecurityEnabled(bool enabled);
111  bool isStrictTransportSecurityEnabled() const;
112  void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString());
113  bool isStrictTransportSecurityStoreEnabled() const;
114  void addStrictTransportSecurityHosts(const QList<QHstsPolicy> &knownHosts);
115  QList<QHstsPolicy> strictTransportSecurityHosts() const;
116 
117  QNetworkReply *head(const QNetworkRequest &request);
122  QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
123  QNetworkReply *deleteResource(const QNetworkRequest &request);
124  QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr);
125  QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data);
126 
127 #if QT_CONFIG(http) || defined(Q_OS_WASM)
130  QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
131 #endif
132 
133 #ifndef QT_NO_SSL
134  void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
135  const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration());
136  void connectToHostEncrypted(const QString &hostName, quint16 port,
137  const QSslConfiguration &sslConfiguration,
138  const QString &peerName);
139 #endif
140  void connectToHost(const QString &hostName, quint16 port = 80);
141 
142  void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
143  QNetworkRequest::RedirectPolicy redirectPolicy() const;
144 
145  bool autoDeleteReplies() const;
146  void setAutoDeleteReplies(bool autoDelete);
147 
148  int transferTimeout() const;
149  void setTransferTimeout(int timeout = QNetworkRequest::DefaultTransferTimeoutConstant);
150 
151 Q_SIGNALS:
152 #ifndef QT_NO_NETWORKPROXY
154 #endif
157 #ifndef QT_NO_SSL
161 #endif
162 
163 protected:
164  virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
165  QIODevice *outgoingData = nullptr);
166 
167 protected Q_SLOTS:
168  QStringList supportedSchemesImplementation() const;
169 
170 private:
172  friend class QNetworkReplyHttpImpl;
174  friend class QNetworkReplyFileImpl;
175 
176 #ifdef Q_OS_WASM
177  friend class QNetworkReplyWasmImpl;
178 #endif
179  Q_DECLARE_PRIVATE(QNetworkAccessManager)
180  Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
181 #ifndef QT_NO_SSL
182  Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
183 #endif
184 };
185 
187 
188 #endif
The QAbstractNetworkCache class provides the interface for cache implementations.
The QAuthenticator class provides an authentication object.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QHstsPolicy class specifies that a host supports HTTP Strict Transport Security policy (HSTS).
Definition: qhstspolicy.h:55
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:70
The QNetworkAccessManager class allows the application to send network requests and receive replies.
void finished(QNetworkReply *reply)
void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator)
void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
void encrypted(QNetworkReply *reply)
void sslErrors(QNetworkReply *reply, const QList< QSslError > &errors)
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
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.
Definition: qnetworkreply.h:63
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QSslConfiguration class holds the configuration and state of an SSL connection.
static QSslConfiguration defaultConfiguration()
The QSslError class provides an SSL error.
Definition: qsslerror.h:57
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
QCache< int, Employee > cache
[0]
#define QString()
Definition: parse-defines.h:51
set set set set set set set macro pixldst1 op
EGLOutputPortEXT port
unsigned short quint16
Definition: qglobal.h:286
GLbitfield GLuint64 timeout
[4]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_MOC_INCLUDE(...)
Definition: qtmetamacros.h:115
#define Q_PRIVATE_SLOT(d, signature)
Definition: qtmetamacros.h:82
#define Q_SIGNALS
Definition: qtmetamacros.h:81
sock connectToHost(url.host(), url.port(80))
QItemEditorFactory * factory
QSizePolicy policy
http post("register.html", data)
http get(QUrl::toPercentEncoding("/index.html"))
QHttpMultiPart * multiPart
[0]
QNetworkRequest request(url)
QNetworkReply * reply
manager setCache(diskCache)
QNetworkProxy proxy
[0]
serverSocket setProxy(QNetworkProxy::NoProxy)
[0]
socket connectToHostEncrypted("imap.example.com", 993)
const QLatin1String storeDir(".")
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent