-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinhttpAPI.h
93 lines (71 loc) · 2.65 KB
/
WinhttpAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef WINHTTP_SIMPLEAPI_WINHTTPAPI_H
#define WINHTTP_SIMPLEAPI_WINHTTPAPI_H
#include <map>
#include <string>
#include <Windows.h>
#include <memory>
#include <utility>
namespace Winhttp {
struct TimeoutT {
int resolveTimeout = 3000;
int connectTimeout = 3000;
int sendTimeout = 3000;
int receiveTimeout = 3000;
};
struct WinhttpOptionT {
DWORD dwOption = 0;
DWORD lpBuffer = 0;
};
struct HttpRequestT {
std::string url;
std::string protocol;
std::string body;
std::string proxy;
std::string proxyBypass;
struct SaveMethodT {
enum MethodE {
STRING_STREAM, FILE_STREAM
};
MethodE downloadMethod;
std::string downloadPath;
SaveMethodT(MethodE DownloadMethod)
: downloadMethod(DownloadMethod) {}
SaveMethodT(MethodE DownloadMethod, std::string DownloadPath)
: downloadMethod(DownloadMethod), downloadPath(std::move(DownloadPath)) {}
};
SaveMethodT saveMethod;
TimeoutT timeout;
WinhttpOptionT winhttpOption;
HttpRequestT()
: saveMethod(SaveMethodT::MethodE::STRING_STREAM) {}
HttpRequestT(std::string Url, std::string Protocol, SaveMethodT SaveMethod = {SaveMethodT::STRING_STREAM})
: url(std::move(Url)), protocol(std::move(Protocol)), saveMethod(std::move(SaveMethod)) {
}
};
struct HttpResponseT {
std::string Body;
std::string Headers;
};
class WinhttpAPI {
private:
std::map<std::string, std::string> headers;
HttpRequestT *pHttpRequest = nullptr;
HttpResponseT *pHttpResponse = nullptr;
public:
WinhttpAPI() = default;
WinhttpAPI(HttpRequestT &HttpRequest,HttpResponseT &HttpResponse)
: pHttpRequest(&HttpRequest), pHttpResponse(&HttpResponse) {}
void Request();
void Request(HttpRequestT &HttpRequest, HttpResponseT &HttpResponse);
bool SetHeader(const std::string &Key, const std::string &Value);
bool SetHeaders(const std::map<std::string, std::string> &KeyValue);
std::string GetHeader(const std::string &Key);
};
}
namespace CodeCvt {
extern std::string WstrToStr(const std::wstring &Src, UINT CodePage = CP_ACP);
extern std::wstring StrToWstr(const std::string &Src, UINT CodePage = CP_ACP);
extern std::unique_ptr<char[]> WstrToStr(wchar_t *Src, UINT CodePage = CP_ACP);
extern std::unique_ptr<wchar_t[]> StrToWstr(char *Src, UINT CodePage = CP_ACP);
}
#endif //WINHTTP_SIMPLEAPI_WINHTTPAPI_H