123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #ifndef INCLUDE_HTTPFUNC_H_
- #define INCLUDE_HTTPFUNC_H_
- #pragma once
- #include <unordered_map>
- #include "RVCComm.h"
- #include "httpTrace_define.hpp"
- using namespace std;
- #pragma pack(1)
- struct CHTTPReq{
- CHTTPReq():m_timeOut(30), m_bZip(false)
- #if defined(_MSC_VER)
- , m_bTransCode(true)
- #else
- , m_bTransCode(false)
- #endif //_MSC_VER
- ,m_printDbg(false), m_withToken(true){}
- virtual ~CHTTPReq(){}
- string m_url;
- int m_timeOut;
- bool m_bZip;
- bool m_bTransCode;
- bool m_printDbg;
- bool m_withToken;
- unordered_map<string, string> m_headers;
- virtual string ToJson() = 0;
- };
- struct CHTTPRet{
- virtual ~CHTTPRet(){}
- int m_sysCode;
- string m_userCode;
- string m_errMsg;
- unordered_map<string, string> m_headers;
- string m_resultData;
- virtual bool Parse(string strData) =0;
- };
- struct CHTTPUploadReq{
- CHTTPUploadReq()
- #if defined(_MSC_VER)
- : m_bTransCode(true)
- #else
- : m_bTransCode(false)
- #endif //_MSC_VER
- , fileContent(NULL), fileContentSize(0),m_timeOut(30),m_printDbg(false){}
- string url;
- string paramContent;
- string fileName;
- bool m_bTransCode;
- byte* fileContent;
- long fileContentSize;
- int m_timeOut;
- bool m_printDbg;
- };
- struct CHTTPUploadRet {
- long httpCode;
- string m_userCode;
- string m_errMsg;
- unordered_map<string, string> m_headers;
- string strBody;
- };
- #pragma pack()
- enum SettingsFlag
- {
- NO_FLAGS = 0x00,
- ENABLE_LOG = 0x01,
- VERIFY_PEER = 0x02,
- VERIFY_HOST = 0x04,
- ALL_FLAGS = 0xFF
- };
- struct fileContentArray
- {
- byte* copyPtr;
- int maxLen;
- int* curLen;
- };
- class IHttpFunc
- {
- public:
- virtual ~IHttpFunc() {}
- //销毁对象
- virtual void Destory() = 0;
- //get请求
- virtual const bool Get(CHTTPReq& req, CHTTPRet& ret, HttpClientTraceLink* pTrace) = 0;
- //post请求
- virtual const bool Post(CHTTPReq& req, CHTTPRet& ret, HttpClientTraceLink* pTrace) = 0;
- //文件块上传
- virtual const bool UploadFileBlock(CHTTPUploadReq& req, CHTTPUploadRet& ret, HttpClientTraceLink* pTrace) = 0;
- //文件块下载
- virtual const bool DownloadFileBlock(const char* url, const char* jsonReqStr, fileContentArray &content, long& httpCode, unordered_map<string, string>& responseHeaders, long timeout, HttpClientTraceLink* pTrace) = 0;
- };
- typedef void (*LogFnCallback)(const char*);
- RVCCOMM_API IHttpFunc* create_http(LogFnCallback oLogger);
- typedef void (*GetTokenCallBack)(std::string &, std::string &, std::string&, std::string&);
- RVCCOMM_API void SetTokenCallBack(GetTokenCallBack t_callBack);
- #endif
|