2019-02-11 10:46:39 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <winhttp.h>
|
|
|
|
|
|
|
|
using InternetHandle = AutoHandle<Functor<WinHttpCloseHandle>>;
|
|
|
|
|
2019-06-13 16:01:29 +08:00
|
|
|
struct HttpRequest
|
2019-02-11 10:46:39 +08:00
|
|
|
{
|
2019-06-13 16:01:29 +08:00
|
|
|
HttpRequest(
|
|
|
|
const wchar_t* agentName,
|
|
|
|
const wchar_t* serverName,
|
|
|
|
const wchar_t* action,
|
|
|
|
const wchar_t* objectName,
|
2020-03-30 10:55:12 +08:00
|
|
|
std::string body = "",
|
|
|
|
const wchar_t* headers = NULL,
|
|
|
|
const wchar_t* referrer = NULL,
|
2019-06-13 16:01:29 +08:00
|
|
|
DWORD requestFlags = WINHTTP_FLAG_SECURE | WINHTTP_FLAG_ESCAPE_DISABLE,
|
|
|
|
const wchar_t* httpVersion = NULL,
|
2020-10-14 08:37:03 +08:00
|
|
|
const wchar_t** acceptTypes = NULL,
|
|
|
|
DWORD port = INTERNET_DEFAULT_PORT
|
2019-06-13 16:01:29 +08:00
|
|
|
);
|
|
|
|
operator bool() { return errorCode == ERROR_SUCCESS; }
|
|
|
|
|
|
|
|
std::wstring response;
|
2020-03-26 19:41:21 +08:00
|
|
|
std::wstring headers;
|
2019-06-13 16:01:29 +08:00
|
|
|
InternetHandle connection = NULL;
|
|
|
|
InternetHandle request = NULL;
|
|
|
|
DWORD errorCode = ERROR_SUCCESS;
|
2019-06-06 08:26:50 +08:00
|
|
|
};
|
2019-06-13 16:01:29 +08:00
|
|
|
|
|
|
|
std::wstring Escape(const std::wstring& text);
|
2020-03-30 10:55:12 +08:00
|
|
|
|
|
|
|
namespace JSON
|
|
|
|
{
|
|
|
|
void Unescape(std::wstring& text);
|
|
|
|
std::string Escape(const std::wstring& text);
|
|
|
|
}
|