23 #pragma comment(lib, "Winhttp.lib")
29 static BOOLEAN ReadRequestString(
30 _In_ HINTERNET Handle,
31 _Out_ _Deref_post_z_cap_(*DataLength) PSTR *Data,
32 _Out_ ULONG *DataLength
36 ULONG allocatedLength;
41 allocatedLength =
sizeof(buffer);
42 data = (PSTR)PhAllocate(allocatedLength);
48 while (WinHttpReadData(Handle, buffer,
PAGE_SIZE, &returnLength))
50 if (returnLength == 0)
53 if (allocatedLength < dataLength + returnLength)
56 data = (PSTR)PhReAllocate(data, allocatedLength);
60 memcpy(data + dataLength, buffer, returnLength);
64 dataLength += returnLength;
67 if (allocatedLength < dataLength + 1)
70 data = (PSTR)PhReAllocate(data, allocatedLength);
76 *DataLength = dataLength;
86 BOOLEAN isSuccess =
FALSE;
88 PSTR xmlBuffer = NULL;
92 HINTERNET connectionHandle = NULL;
93 HINTERNET requestHandle = NULL;
94 HINTERNET sessionHandle = NULL;
96 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig = { 0 };
119 WinHttpGetIEProxyConfigForCurrentUser(&proxyConfig);
122 if (!(sessionHandle = WinHttpOpen(
124 proxyConfig.lpszProxy != NULL ? WINHTTP_ACCESS_TYPE_NAMED_PROXY : WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
125 proxyConfig.lpszProxy,
126 proxyConfig.lpszProxyBypass,
133 if (!(connectionHandle = WinHttpConnect(
136 INTERNET_DEFAULT_HTTP_PORT,
146 if (!(requestHandle = WinHttpOpenRequest(
149 whoisHttpGetString->
Buffer,
152 WINHTTP_DEFAULT_ACCEPT_TYPES,
159 if (!WinHttpAddRequestHeaders(requestHandle, L
"Accept: text/plain", -1L, 0))
162 if (!WinHttpSendRequest(
164 WINHTTP_NO_ADDITIONAL_HEADERS, 0,
165 WINHTTP_NO_REQUEST_DATA, 0,
166 WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, 0
172 if (!WinHttpReceiveResponse(requestHandle, NULL))
175 if (!ReadRequestString(requestHandle, &xmlBuffer, &xmlLength))
191 if (whoisHttpGetString)
195 WinHttpCloseHandle(requestHandle);
197 if (connectionHandle)
198 WinHttpCloseHandle(connectionHandle);
201 WinHttpCloseHandle(sessionHandle);
204 return STATUS_SUCCESS;