98 lines
3.3 KiB
C++
98 lines
3.3 KiB
C++
#ifndef DATAT_RANS_HPP_
|
||
#define DATAT_RANS_HPP_
|
||
|
||
#include <stdio.h>
|
||
#include <string>
|
||
#include <curl/curl.h>
|
||
#include <sys/socket.h>
|
||
#include <netinet/in.h>
|
||
#include <stdlib.h>
|
||
#include <boost/container/detail/singleton.hpp>
|
||
#include "common/global.hpp"
|
||
|
||
#define BUFFER_SIZE 4096
|
||
|
||
#define IP "127.0.0.1"
|
||
#define PORT 12345
|
||
|
||
struct DownloadFile {
|
||
const char *filename;
|
||
FILE *stream;
|
||
};
|
||
|
||
class DataTrans {
|
||
public:
|
||
DataTrans();
|
||
~DataTrans();
|
||
|
||
/**
|
||
* @brief HTTP POST请求
|
||
* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
|
||
* @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @return 返回是否Post成功
|
||
*/
|
||
int Post(const std::string &strUrl, const std::string &strPost, std::string &strResponse);
|
||
|
||
/**
|
||
* @brief HTTP GET请求
|
||
* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @return 返回是否Post成功
|
||
*/
|
||
|
||
int Get(const std::string &strUrl, std::string &strResponse);
|
||
|
||
/**
|
||
* @brief HTTPS POST请求,无证书版本
|
||
* @param strUrl 输入参数,请求的Url地址,如:https://www.baidu.com
|
||
* @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
|
||
* @return 返回是否Post成功
|
||
*/
|
||
|
||
int Posts(const std::string &strUrl, const std::string &strPost, std::string &strResponse, const char *pCaPath = NULL);
|
||
|
||
/**
|
||
* @brief HTTPS GET请求,无证书版本
|
||
* @param strUrl 输入参数,请求的Url地址,如:https://www.baidu.com
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
|
||
* @return 返回是否Post成功
|
||
*/
|
||
|
||
int Gets(const std::string &strUrl, std::string &strResponse, const char *pCaPath = NULL);
|
||
|
||
/**
|
||
* @brief HTTP 上传文件
|
||
* @param strUrl 输入参数,请求的Url地址,如:http://localcast:8080/source
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @param filename 文件的绝对地址,如/home/usr/cidw.log
|
||
* @return 函数返回0执行成功
|
||
*/
|
||
|
||
int upload_file(const std::string &strUrl, const std::string &filename, std::string &strResponse);
|
||
|
||
/**
|
||
* @brief 下载文件,如果板子支持wget下载会方便很多接口保留,待确认后在开发
|
||
* @param strUrl 输入参数,请求的Url地址,如:http://localcast:8080/source
|
||
* @param strResponse 输出参数,返回的内容
|
||
* @param filename 文件的绝对地址,如/home/usr/cidw.log
|
||
* @return 函数返回0执行成功
|
||
*/
|
||
|
||
// int download_file(const std::string &strUrl, const std::string &filename, std::string &strResponse);
|
||
|
||
int download(char *pFilename, std::string &strUrl, std::string &strResponse, bool bDownload);
|
||
int dl_curl_post_req(const std::string &url, const std::string &postParams, std::string &filename);
|
||
|
||
void SetDebug(bool bDebug);
|
||
|
||
private:
|
||
bool debug_;
|
||
};
|
||
|
||
typedef boost::container::dtl::singleton_default<DataTrans> data_trans;
|
||
#endif // DATAT_RANS_HPP_
|