tv_rename/network.hpp

47 lines
825 B
C++
Raw Permalink 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
2020-01-17 13:01:10 +00:00
#include <Windows.h>
#include <WinInet.h>
2020-01-15 15:30:30 +00:00
#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 21:23:11 +00:00
Request();
2020-01-15 15:30:30 +00:00
~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();
2020-01-15 21:23:11 +00:00
void setServer( const string &server );
2020-01-17 13:01:10 +00:00
int lastResponseCode();
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-04-16 11:23:02 +00:00
HINTERNET _hInternet;
2020-01-15 15:30:30 +00:00
HINTERNET _hConnect = nullptr;
std::wstring _headers = L"";
2020-01-17 13:01:10 +00:00
int status_code{};
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;
2020-01-15 21:23:11 +00:00
string _server;
2019-02-04 16:39:48 +00:00
#endif
2019-01-19 12:40:10 +00:00
};
#endif