CHttpClient.h 1.7 KB

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