synchttp.h 919 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef SYNCHTTP_H
  2. #define SYNCHTTP_H
  3. #include <QEventLoop>
  4. #include <QNetworkAccessManager>
  5. #include <QNetworkReply>
  6. #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  7. #include <QtCore/QTextCodec>
  8. #else
  9. #include <QtCore5Compat/QTextCodec>
  10. #endif
  11. #include <QWidget>
  12. class SyncHttp : public QWidget
  13. {
  14. Q_OBJECT
  15. public:
  16. explicit SyncHttp(QWidget* parent = nullptr);
  17. bool downloadFile(QString url, QString path);
  18. void setIpAndPort(const QString& ip, int port, QString protocol = "http");
  19. int postJsonData(const QString& params, QByteArray& data, QByteArray& ret);
  20. int postJsonData2(const QString& url, QByteArray& data, QByteArray& ret);
  21. int getJsonData(const QString& params, QByteArray& ret);
  22. int getJsonData(const QString& url, const QString& params, QByteArray& ret);
  23. int getHtmlData(const QString& url, QByteArray& ret);
  24. signals:
  25. private:
  26. QString m_baseUrl;
  27. };
  28. #endif // SYNCHTTP_H