tv_rename/network.hpp

45 lines
792 B
C++
Raw Normal View History

2019-01-19 12:40:10 +00:00
#ifndef NETWORK_HPP
#define NETWORK_HPP
2019-02-04 16:39:48 +00:00
#ifdef _WIN32
#include <Windows.h>
2020-01-15 15:30:30 +00:00
#include <WinInet.h>
#include <string>
2019-02-04 16:39:48 +00:00
using string = std::wstring;
#else
2019-01-19 12:40:10 +00:00
#include <curl/curl.h>
#include <string>
2019-01-19 12:40:10 +00:00
2019-02-04 16:39:48 +00:00
using string = std::string;
#endif
2020-01-15 15:30:30 +00:00
class Request {
2019-01-19 12:40:10 +00:00
public:
2020-01-15 15:30:30 +00:00
Request() = delete;
Request( const string &server );
~Request();
std::string get( const string &url );
2020-01-15 15:30:30 +00:00
std::string post( const string &url, const std::string &data );
void addHeader( const string &header );
void clearHeader();
2020-01-15 15:30:30 +00:00
bool initSuccessful();
2019-02-04 16:39:48 +00:00
2019-01-19 12:40:10 +00:00
private:
2019-02-04 16:39:48 +00:00
#ifdef _WIN32
2020-01-15 15:30:30 +00:00
HINTERNET _hInternet = nullptr;
HINTERNET _hConnect = nullptr;
std::wstring _headers = L"";
2019-02-04 16:39:48 +00:00
#else
2020-01-15 15:30:30 +00:00
CURL *_curl_handle = nullptr;
struct curl_slist *_chunk = nullptr;
const string _server;
2019-02-04 16:39:48 +00:00
#endif
2019-01-19 12:40:10 +00:00
};
#endif