[嗨,我正尝试使用WinInet和Costum用户代理下载某些内容,问题是我在HttpSendRequestA上失败,返回的错误为0我不知道此错误是什么意思,我已经尝试过查找但什么都没有发生我使用std::to_string(GetLastError());
收到错误这是代码框[]
std::string GetUrlData(const std::string& resource, const std::string& host) { std::string output = ""; output.clear(); HINTERNET hIntSession = InternetOpenA("token", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (!hIntSession) { return "ERROR: Session Cannot Start"; } HINTERNET hHttpSession = InternetConnectA(hIntSession, host.c_str(), 80, 0, 0, INTERNET_SERVICE_HTTP, 0, NULL); if (!hHttpSession) { InternetCloseHandle(hIntSession); return "ERROR: Cannot Connect To Internet"; } HINTERNET hHttpRequest = HttpOpenRequestA(hHttpSession, "GET", resource.c_str(), 0, 0, 0, INTERNET_FLAG_RELOAD, 0); if (!hHttpRequest) { InternetCloseHandle(hHttpSession); InternetCloseHandle(hIntSession); return "ERROR: Http Request Failed"; } // const char* szHeaders = "User-Agent: Mozzila\r\n"; if (!HttpSendRequestA(hHttpRequest, NULL, 0, NULL, 0)) { InternetCloseHandle(hHttpRequest); InternetCloseHandle(hHttpSession); InternetCloseHandle(hIntSession); return "ERROR: Http Request Failed 2"; } char szBuffer[1024]; DWORD dwRead = 0; do { if (!InternetReadFile(hHttpRequest, szBuffer, sizeof(szBuffer), &dwRead)) { InternetCloseHandle(hHttpRequest); InternetCloseHandle(hHttpSession); InternetCloseHandle(hIntSession); return "ERROR: Cannot Download"; } if (dwRead == 0) break; output.append(szBuffer, dwRead); } while (true); return output; }
我称此功能为std :: string
data = GetUrlData("http://example.com/", "http://example.com/");
[嗨,我正尝试使用WinInet和Costum用户代理下载某些内容,问题是我在HttpSendRequestA失败,返回的错误是0,我不知道此错误意味着我已经尝试过...
host
参数应仅是主机名,而不是完整的URL。