12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef CHTTPINTERCEPTOR_H
- #define CHTTPINTERCEPTOR_H
- #include <QString>
- #include <QStringList>
- #include <thread>
- #include <mutex>
- #include "CHttpClient.h"
- #include "httpDataDef.h"
- #include "json/json.h"
- class CHttpInterceptor
- {
- public:
- CHttpInterceptor();
- ~CHttpInterceptor();
- void init(QString sIp, QString sPort, bool bUseHttps = false);
- QString getHttpUrl() const;
- void post(CHttpRequestPackage requestPkg);
- void get(CHttpRequestPackage requestPkg);
- void getUrl(CHttpRequestPackage requestPkg);
- void put(CHttpRequestPackage requestPkg);
- void downLoad(CHttpRequestPackage requestPkg);
- virtual void requestProc(const CHttpRequestPackage requestPkg)=0;
- protected:
- void initHeads(const CHttpRequestPackage &requestPkg);
- bool doPost(const CHttpRequestPackage &requestPkg, std::string &sResponseStr, int &nCode);
- bool doGet(const CHttpRequestPackage &requestPkg, std::string &sResponseStr, int &nCode);
- bool doPut(const CHttpRequestPackage &requestPkg, std::string &sResponseStr, int &nCode);
- bool downLoadFile(std::string uri, std::string sFileName, int &nResCode);
- private:
- void threadProc();
- std::thread m_thread;
- bool m_bIsRun;
- std::mutex m_mReqPkgMutex;
- std::list<CHttpRequestPackage> m_mReqPkgList;
- CHttpClient m_httpClient;
- QString m_sUrl = "";
- QString m_wxUrl = "";
- };
- #endif // CHTTPINTERCEPTOR_H
|