WLG/datatransfer/data_trans.hpp

107 lines
3.5 KiB
C++
Raw Normal View History

2024-10-22 19:04:25 +08:00
#ifndef DATATRANS_HPP_
#define DATATRANS_HPP_
#include <stdio.h>
#include <string>
#include <curl/curl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include "../common/SH_global.h"
#define BUFFER_SIZE 4096
#define IP "127.0.0.1"
#define PORT 12345
class DataTrans : public MySingleton<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);
/**
* @brief socket发送文件
* @param filename
* @return 0
*/
int Send_file_socket(const std::string &filename);
/**
* @brief socket发送文件夹下所有文件
* @param dirname
* @return 0
*/
int Send_Dir_socket(const char *dirname);
int download(char *pFilename, string &strUrl, string &strResponse, bool bDownload);
int dl_curl_post_req(const string &url, const string &postParams, string &filename);
public:
void SetDebug(bool bDebug);
private:
bool m_bDebug;
};
extern DataTrans *pDataTrans;
#endif