WLG/datatransfer/data_trans.hpp

98 lines
3.4 KiB
C++
Raw Permalink Normal View History

2025-01-23 11:13:58 +08:00
#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=val12=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=val12=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_