HttpClient.h 905 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef HTTPCLIENT_H
  2. #define HTTPCLIENT_H
  3. #include <QObject>
  4. #include <QNetworkAccessManager>
  5. #include <QNetworkReply>
  6. #include <QUrl>
  7. class HttpClient : public QObject {
  8. Q_OBJECT
  9. public:
  10. explicit HttpClient(QObject *parent = nullptr);
  11. // 发送 GET 请求的接口
  12. void sendHttpGetRequest(const QUrl &url);
  13. void sendHttpGetAddress(const QUrl &url);
  14. signals:
  15. // 请求成功后发出的信号
  16. void httpGetFinished(const QJsonDocument &responseData,const QUrl &url);
  17. // 请求失败后发出的信号
  18. void httpErrorOccurred(const QString &errorString);
  19. private slots:
  20. void onGetFinished();
  21. void onNetworkError(QNetworkReply::NetworkError error);
  22. void onSslErrors(const QList<QSslError> &errors);
  23. void onGetAddress();
  24. private:
  25. QNetworkAccessManager *m_networkManager;
  26. QUrl m_currenturl;
  27. QUrl m_currenturl2;
  28. };
  29. #endif // HTTPCLIENT_H