dmphttpbase.h 2.3 KB
/**************************************************************************
* file:              dmphttpbase.h

* Author:            lijiahuan
* Date:              2021-12-09 17:41:00
* Email:             jiahuanl@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/
#ifndef __dmphttpbase_h__
#define __dmphttpbase_h__
#include <iostream>
#include <boost/asio.hpp>
namespace DmpHttp
{ 
    #define HTTP_SUCCESS       (0)          // 操作成功
    #define HTTP_ERROR_UNKNOWN      (-1)         // 未知的错误
    #define HTTP_ERROR_NETWORK      (-2)         // 网络连接失败
    #define HTTP_ERROR_HTTP_HEAD    (-3)         // 未找到协议头 http || https 

    #define HTTP_ERROR_SERVICE      (-1000)      // 服务器请求失败
    #define HTTP_ERROR_LOGIN        (-1001)      // 登录失败
    #define HTTP_ERROR_ID           (-1002)      // 企业ID错误
    #define HTTP_ERROR_USER         (-1003)      // 帐号不存在
    #define HTTP_ERROR_PASSWORD     (-1004)      // 密码错误

    #define HTTP_ERROR_PARAMETER    (1)          // 参数错误
    #define HTTP_ERROR_PHONE        (2)          // 电话号码错误
    #define HTTP_ERROR_MESSAGE      (3)          // 短信有屏蔽字段
    #define HTTP_ERROR_FUNCTION     (4)          // 当前平台不支持这个功能

    class DmpHttpBase 
    {
    public:
        DmpHttpBase();
        virtual ~DmpHttpBase();  
	    // Post请求
	    virtual int post(const std::string& url) = 0;
        virtual int post(const std::string& url, std::string& postData)= 0;
        // get请求
        virtual int get(const std::string& url) = 0;  
	    virtual std::string getResponse(void) = 0;

    protected:
        typedef int(*pBuildRequest)(const std::string&, const std::string&,std::ostream&);

        static int parseUrl(const std::string& url, std::string& out_server,
		            std::string& out_port, std::string& out_path);
        static int buildPostRequest(const std::string& server, const std::string& path,
					std::ostream& out_request);
        static int buildGetRequest(const std::string& server, const std::string& path,
					std::ostream& out_request);   
    };
}




#endif //__dmphttpbase_h__