在这里插入代码片
#ifndef _CURL_INTERFACE_H_
#define _CURL_INTERFACE_H_
#include<string>
#include<list>
#include<stdio.h>
#include<strstream>
#include<sys/stat.h>
#include "curl.h"
#define CURL_API __declspec(dllexport)
typedef enum
{
HTTP_RESPONSE_HEAD,//获取响应报文的HTTP头
HTTP_RESPONSE_BODY,//获取响应报文的HTTP正文
HTTP_RESPONSE_ALL,//获取响应报文的所有内容
}HTTP_CONTROL_CODE;
#ifdef __cplusplus
extern "C" {
#endif
//HTTP POST请求
//strUrl 输入参数,请求的url地址
//strCookie 输入参数,请求报文中的Cookie值,可为空字符串
//strPost 输入参数,post报文的提交值
//strResponse 输出参数 响应报文
//iType 输入参数 响应报文的返回类型
//return int 成功返回0,失败返回错误码
int libHttpPost(const std::string& strUrl, const std::string& strCookie, const std::string& strPost, \
std::string& strResponse, int iType = HTTP_RESPONSE_ALL);
int libHttpPostEx(const std::string& strUrl, const std::list<std::string>& headers,
const std::string& strCookie, const std::string& strPost, std::string& strResponse,
int iType = HTTP_RESPONSE_ALL, const char* pCaPath = NULL);
int libHttpGet(const std::string& strUrl, const std::string& strCookie,
std::string& strResponse, int iType = HTTP_RESPONSE_ALL);
int libHttpGetEx(const std::string& strUrl, const std::list<std::string>& headers,
const std::string& strCookie, std::string& strResponse, int iType = HTTP_RESPONSE_ALL);
//const char* pCaPath 输入参数,CA证书的路径, 如果为NULL则不验证服务器证书的有效性
int libHttpsPost(const std::string& strUrl, const std::list<std::string>& headers,
const std::string& strCookie, const std::string& strPost, std::string& strResponse,
int iType = HTTP_RESPONSE_ALL, const char* pCaPath = NULL);
int libHttpsGet(const std::string& strUrl, const std::list<std::string>& headers,
const std::string& strCookie, std::string& strResponse,
int iType = HTTP_RESPONSE_ALL, const char* pCaPath = NULL);
#endif // !_CURL_INTERFACE_H_
基于libcUrl库HTTP协议封装(1)
最新推荐文章于 2022-05-24 13:37:59 发布