CHttpClient.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. using namespace std;
  3. class CHttpClient
  4. {
  5. public:
  6. CHttpClient();
  7. ~CHttpClient();
  8. public:
  9. /**
  10. * @brief HTTP POST请求
  11. * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
  12. * @param strPost 输入参数,使用如下格式para1=val1&para2=val2&…
  13. * @param strResponse 输出参数,返回的内容
  14. * @return 返回是否Post成功
  15. */
  16. int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
  17. /**
  18. * @brief HTTP GET请求
  19. * @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
  20. * @param strResponse 输出参数,返回的内容
  21. * @return 返回是否Post成功
  22. */
  23. int Get(const std::string & strUrl, std::string & strResponse);
  24. /**
  25. * @brief HTTPS POST请求,无证书版本
  26. * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
  27. * @param strPost 输入参数,使用如下格式ppara1=val1&para2=val2&…
  28. * @param strResponse 输出参数,返回的内容
  29. * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
  30. * @return 返回是否Post成功
  31. */
  32. int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
  33. /**
  34. * @brief HTTPS GET请求,无证书版本
  35. * @param strUrl 输入参数,请求的Url地址,如:https://www.alipay.com
  36. * @param strResponse 输出参数,返回的内容
  37. * @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
  38. * @return 返回是否Post成功
  39. */
  40. int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
  41. public:
  42. void SetDebug(bool bDebug);
  43. private:
  44. bool m_bDebug;
  45. };