33 #pragma comment(lib, "Wininet.lib") 35 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 36 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "net.http" 45 bool final_res =
false;
50 HINTERNET hinet = ::InternetOpenA(SHARED_JOBSCOMMON_HTTP_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
53 int err = ::GetLastError();
54 LOG_PRINT(
"Failed to call InternetOpenA, \nError: " << err <<
" " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
59 DWORD dwBuffLen =
sizeof(dwFlags);
63 dwFlags |= INTERNET_FLAG_IGNORE_CERT_CN_INVALID|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|
64 INTERNET_FLAG_PRAGMA_NOCACHE | SECURITY_FLAG_IGNORE_UNKNOWN_CA|INTERNET_FLAG_SECURE;
67 dwFlags |= INTERNET_FLAG_PRAGMA_NOCACHE;
71 int port = url_obj.GetPortNumber();
74 HINTERNET hsession = ::InternetConnectA(hinet,
string_encoding::convert_to_ansii(url_obj.GetHostName()).c_str(),
port, usr.c_str(), psw.c_str(), INTERNET_SERVICE_HTTP, dwFlags, NULL);
79 HINTERNET hrequest = ::HttpOpenRequestA(hsession, use_post?
"POST":NULL, uri.c_str(), NULL, NULL,NULL, dwFlags, NULL);
84 res = ::HttpSendRequestA(hrequest, NULL, 0, NULL, 0);
89 int err = ::GetLastError();
90 LOG_PRINT(
"Failed to call HttpSendRequestA, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
95 DWORD buf_len =
sizeof(code);
97 res = ::HttpQueryInfo(hrequest, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE, &code, &buf_len, &index);
102 int err = ::GetLastError();
103 LOG_PRINT(
"Failed to call HttpQueryInfo, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
106 if(code < 200 || code > 299)
108 LOG_PRINT(
"Wrong server response, HttpQueryInfo returned statuse code" << code , LOG_LEVEL_0);
113 char buff[100000] = {0};
117 res = ::InternetReadFile(hrequest, buff,
sizeof(buff), &readed);
120 int err = ::GetLastError();
121 LOG_PRINT(
"Failed to call InternetReadFile, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
126 http_response_body.append(buff, readed);
139 res = ::InternetCloseHandle(hrequest);
142 int err = ::GetLastError();
143 LOG_PRINT(
"Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
152 int err = ::GetLastError();
153 LOG_PRINT(
"Failed to call InternetOpenUrlA, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
157 res = ::InternetCloseHandle(hsession);
160 int err = ::GetLastError();
161 LOG_PRINT(
"Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
165 int err = ::GetLastError();
166 LOG_PRINT(
"Failed to call InternetConnectA(" <<
string_encoding::convert_to_ansii(url_obj.GetHostName()) <<
", port " <<
port <<
" \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
171 res = ::InternetCloseHandle(hinet);
174 int err = ::GetLastError();
175 LOG_PRINT(
"Failed to call InternetCloseHandle, \nError: " << log_space::get_win32_err_descr(err), LOG_LEVEL_0);
std::string convert_to_ansii(const std::wstring &str_from)
boost::endian::big_uint16_t port
target_string convert_to_t(const std::wstring &str_from)
bool http_ssl_invoke(const std::string &url, const std::string usr, const std::string psw, std::string &http_response_body, bool use_post=false)