QtHttps.h 819 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef QTHTTPS_H
  2. #define QTHTTPS_H
  3. #include <QObject>
  4. #include <QNetworkReply>
  5. #include <QNetworkAccessManager>
  6. #include <QNetworkRequest>
  7. #include <QFile>
  8. class QtHttps : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit QtHttps(QObject *parent = nullptr);
  13. ~QtHttps();
  14. bool Get(const QString &url);
  15. bool GetHead(const QString &url);
  16. void Post(const QString &url, const QByteArray &data);
  17. void downloadFile(const QString &url, const QString &filePath);
  18. private slots:
  19. void do_replyFinished();
  20. void do_replyReadyRead();
  21. void do_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  22. private:
  23. QNetworkAccessManager *m_manager = nullptr;
  24. QNetworkReply *m_reply = nullptr;
  25. QFile *m_file = nullptr; /* 保存临时文件 */
  26. };
  27. #endif /* QTHTTPS_H */