123456789101112131415161718192021222324252627282930313233343536373839 |
- #ifndef HTTPCLIENT_H
- #define HTTPCLIENT_H
- #include <QObject>
- #include <QNetworkAccessManager>
- #include <QNetworkReply>
- #include <QUrl>
- class HttpClient : public QObject {
- Q_OBJECT
- public:
- explicit HttpClient(QObject *parent = nullptr);
- // 发送 GET 请求的接口
- void sendHttpGetRequest(const QUrl &url);
- void sendHttpGetAddress(const QUrl &url);
- signals:
- // 请求成功后发出的信号
- void httpGetFinished(const QJsonDocument &responseData,const QUrl &url);
- // 请求失败后发出的信号
- void httpErrorOccurred(const QString &errorString);
- private slots:
- void onGetFinished();
- void onNetworkError(QNetworkReply::NetworkError error);
- void onSslErrors(const QList<QSslError> &errors);
- void onGetAddress();
- private:
- QNetworkAccessManager *m_networkManager;
- QUrl m_currenturl;
- QUrl m_currenturl2;
- };
- #endif // HTTPCLIENT_H
|