HttpSession.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "Poco/Net/HTTPClientSession.h"
  3. #include "Poco/Net/HTTPSClientSession.h"
  4. #include "Poco/Net/HTTPRequest.h"
  5. #include "Poco/Net/HTTPResponse.h"
  6. #include "Poco/Net/Context.h"
  7. #include <istream>
  8. #include <ostream>
  9. #include "PhmsRequest.h"
  10. #include "PhmsResponse.h"
  11. #include "NetConfig.h"
  12. using Poco::Net::HTTPClientSession;
  13. using Poco::Net::HTTPSClientSession;
  14. using Poco::Net::HTTPRequest;
  15. using Poco::Net::HTTPResponse;
  16. using Poco::Net::HTTPMessage;
  17. using Poco::Net::Context;
  18. class CHttpSession
  19. {
  20. public:
  21. CHttpSession(void);
  22. CHttpSession(bool bSsl);
  23. CHttpSession(CNetConfig netConfig);
  24. ~CHttpSession(void);
  25. private:
  26. bool m_bSsl;
  27. HTTPClientSession* m_pSession;
  28. Context::Ptr m_pContext;
  29. public:
  30. //Getter
  31. bool GetSsl();
  32. HTTPClientSession* GetHttpClientSession();
  33. int ExecuteHttpSession(CNetConfig& netConfig, CPhmsRequest& phmsRequest, istream* & pInputStream);
  34. //该接口用于非Phms协议的Http请求,用于直接请求某资源,比如http直接请求xml升级配置文件或其他文件,不通过php
  35. int ExecuteNoPhmsHttpSession(CNetConfig& netConfig, istream* & pInputStream, int bContinue, string stringLocalFilePath="");
  36. //该接口用于非Phms协议的Http请求,比如使用Post提交Form表单,通过php(暂时不支持附带文件的表单,以后有需求可以扩充)
  37. int ExecuteFormHttpSession(CNetConfig& netConfig, map<string, string> mapParam, istream* & pInputStream);
  38. //该接口用于非Phms协议的Http请求,比如使用Post提交Form表单,可选附带或者不附带文件,通过php等脚本
  39. int ExecuteFormHttpSession(CNetConfig& netConfig, map<string, string> mapParam, string stringLocalFilePath, istream* & pInputStream);
  40. //该接口用于非Phms协议的Http请求,比如提交xml,用于东亚医讯接口或用于心界的接口
  41. int ExecuteXmlHttpSession(CNetConfig& netConfig, string stringXmlContent, istream* & pInputStream);
  42. //该接口用于非Phms协议的Http请求,用于使用GET方式提交参数
  43. int ExeceteGetHttpSession(CNetConfig& netConfig, map<string, string> mapParam, istream* & pInputStream);
  44. //该接口用于通用POST请求,参数中决定Content-Type、HttpBody以及URL Param
  45. int ExeceteCommonPostSession(CNetConfig& netConfig, map<string, string> mapParam, string stringContentType, string stringHttpBody, istream* & pInputStream);
  46. int GetHttpExceptionInfo(int& nCode, string& msgName, string& msgText);
  47. int AbortSession();
  48. private:
  49. int SetNetWork(CNetConfig& netConfig);
  50. int GenerateHttpRequest(CNetConfig& netConfig, CPhmsRequest& phmsRequest, string stringBoundary, HTTPRequest& httpRequest);
  51. int GenerateNoPhmsHttpRequest(CNetConfig& netConfig, HTTPRequest& httpRequest, int bContinue, string stringLocalFilePath="");
  52. int GenerateFormHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string& stringParam, HTTPRequest& httpRequest);
  53. int GenerateFormHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string stringLocalFilePath, string stringBoundary, HTTPRequest& httpRequest);
  54. int GeneratePostHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, string stringContentType, string stringHttpBody, HTTPRequest& httpRequest);
  55. int GenerateXmlHttpRequest(CNetConfig& netConfig, string stringXmlContent, HTTPRequest& httpRequest);
  56. int GenerateGetHttpRequest(CNetConfig& netConfig, map<string, string> mapParam, HTTPRequest& httpRequest);
  57. int SendPhms(ostream& outputStream, string stringBoundary, CPhmsRequest& phmsRequest);
  58. int SendPostMapAndFile(ostream& outputStream, string stringBoundary, map<string, string> mapParam, string stringLocalFilePath);
  59. int HandleHttpResponse(HTTPResponse& httpResponse);
  60. };