123456789101112131415161718192021222324252627282930313233343536 |
- #ifndef QTHTTPS_H
- #define QTHTTPS_H
- #include <QObject>
- #include <QNetworkReply>
- #include <QNetworkAccessManager>
- #include <QNetworkRequest>
- #include <QFile>
- class QtHttps : public QObject
- {
- Q_OBJECT
- public:
- explicit QtHttps(QObject *parent = nullptr);
- ~QtHttps();
- bool Get(const QString &url);
- bool GetHead(const QString &url);
- void Post(const QString &url, const QByteArray &data);
- void downloadFile(const QString &url, const QString &filePath);
- private slots:
- void do_replyFinished();
- void do_replyReadyRead();
- void do_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- private:
- QNetworkAccessManager *m_manager = nullptr;
- QNetworkReply *m_reply = nullptr;
- QFile *m_file = nullptr; /* 保存临时文件 */
- };
- #endif /* QTHTTPS_H */
|