1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #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);
- signals:
- void signal_replyFinished();
- void signal_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- private slots:
- void do_replyFinished();
- void do_replyReadyRead();
- void do_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
- void do_error(QNetworkReply::NetworkError code);
- private:
- QNetworkAccessManager *m_manager = nullptr;
- QNetworkReply *m_reply = nullptr;
- QFile *m_file = nullptr; /* 保存临时文件 */
- };
- #endif /* QTHTTPS_H */
|