//WinINet HTTPS Get // https请求:https://github.com/netdata/netdata/blob/master/CMakeLists.txt #include<iostream> #include<Windows.h> #include<WinInet.h> #pragma comment(lib,"WinInet.lib") int main() { HINTERNET hOpen = InternetOpen(TEXT("KaikiUpdate"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);//打开连接,获得Internet句柄 if (!hOpen) std::cout << "Error InternetOpen.\n"; HINTERNET hConnect = InternetConnect(hOpen, TEXT("github.com"), INTERNET_DEFAULT_HTTPS_PORT, TEXT(""), TEXT(""), INTERNET_SERVICE_HTTP, 0, 0);//连接,获得连接句柄 if (!hConnect) { std::cout << "Error InternetConnect.\n"; return -1; } HINTERNET hReq = HttpOpenRequest(hConnect, TEXT("GET"), TEXT("netdata/netdata/blob/master/CMakeLists.txt"), HTTP_VERSION, TEXT(""), NULL, INTERNET_FLAG_SECURE, 0);//打开请求,获得请求句柄 if (!hReq) { std::cout << "Error HttpOpenRequest.\n"; return -1; } BOOL status = HttpSendRequest(hReq, NULL, 0, NULL, 0);//发送 if (status == FALSE) { std::cout << "Error HttpSendRequest.\n";//断网时在这里出错 return -1; } char szBuffer[1024] = ""; DWORD dwByteRead = 0; // FILE* fp = NULL; // fopen_s(&fp, "dl.txt", "wb"); do { status = InternetReadFile(hReq, szBuffer, ARRAYSIZE(szBuffer), &dwByteRead); if (status == FALSE)std::cout << "Error InternetReadFile.\n"; else std::cout << szBuffer; std::cout << szBuffer; // fwrite(szBuffer, dwByteRead, 1, fp); ZeroMemory(szBuffer, dwByteRead); } while (dwByteRead); //fclose(fp); InternetCloseHandle(hReq); InternetCloseHandle(hConnect); InternetCloseHandle(hOpen); return 0; }
标签:https,hOpen,lib,NULL,openssl,netdata,include,wininet From: https://www.cnblogs.com/bonelee/p/17008257.html