123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef __CURLCLIENT__
- #define __CURLCLIENT__
- #include <string>
- #include <vector>
- using namespace std;
- #ifndef _UNICODE
- typedef string TString;
- #else
- typedef wstring TString;
- #endif
- #pragma once
- namespace utilitySdk
- {
- class __declspec(dllexport) CCurlClient
- {
- public:
- CCurlClient(void);
- ~CCurlClient(void);
- public:
- INT Initialize();
- /**
- * @brief HTTP POST请求
- * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
- * @param strPost 输入参数,使用如下格式para1=val1?2=val2&…
- * @param strResponse 输出参数,返回的内容
- * @return 返回是否Post成功
- */
- int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
- int Post(IN LPCTSTR lpUrl, IN LPCTSTR lpPost, OUT LPTSTR lpResponse, IN CONST INT& nMaxlen);
- int Post(IN CString& strUrl, IN CString& strPost, OUT CString& strResponse);
- /**
- * @brief HTTP GET请求
- * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
- * @param strResponse 输出参数,返回的内容
- * @return 返回是否Post成功
- */
- int Get(const std::string & strUrl, std::string & strResponse);
- int Get(IN LPCTSTR lpUrl, OUT LPTSTR lpResponse, IN CONST INT& nMaxlen);
- int Get(IN CString& strUrl, OUT CString& strResponse);
- /**
- * @brief HTTPS POST请求,无证书版本
- * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
- * @param strPost 输入参数,使用如下格式para1=val1?2=val2&…
- * @param strResponse 输出参数,返回的内容
- * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
- * @return 返回是否Post成功
- */
- int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
- int Posts(IN LPCTSTR lpUrl, IN LPCTSTR lpPost, OUT LPTSTR lpResponse, IN CONST INT& nMaxlen, IN LPCTSTR lpCaPath = NULL);
- int Posts(IN CString& strUrl, IN CString& strPost, OUT CString& strResponse, IN const CString& strCaPath = _T(""));
- /**
- * @brief HTTPS GET请求,无证书版本
- * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
- * @param strResponse 输出参数,返回的内容
- * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
- * @return 返回是否Post成功
- */
- int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
- int Gets(IN LPCTSTR lpUrl, OUT LPTSTR lpResponse, IN CONST INT& nMaxlen, IN LPCTSTR lpCaPath = NULL);
- int Gets(IN CString& strUrl, OUT CString& strResponse, IN const CString& strCaPath = _T(""));
- public:
- void SetDebug(bool bDebug);
- private:
- bool m_bDebug;
- static size_t OnWriteData(const void *ptr, size_t size, size_t nmemb, std::string *stream);
- };
- };
- #endif
|