#ifndef INCLUDE_HTTPFUNC_H_ #define INCLUDE_HTTPFUNC_H_ #pragma once #include #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 m_headers; virtual string ToJson() = 0; }; struct CHTTPRet{ virtual ~CHTTPRet(){} int m_sysCode; string m_userCode; string m_errMsg; unordered_map 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 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) = 0; //文件块下载 virtual const bool DownloadFileBlock(const char* url, const char* jsonReqStr, fileContentArray &content, long& httpCode, unordered_map& responseHeaders, long timeout) = 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