perl
view release on metacpan or search on metacpan
cpan/Win32/Win32.xs view on Meta::CPAN
if (bParsed) {
New(0, hostName, urlComp.dwHostNameLength + 1, WCHAR);
wcsncpy(hostName, urlComp.lpszHostName, urlComp.dwHostNameLength);
hostName[urlComp.dwHostNameLength] = 0;
New(0, urlPath, urlComp.dwUrlPathLength + urlComp.dwExtraInfoLength + 1, WCHAR);
wcsncpy(urlPath, urlComp.lpszUrlPath, urlComp.dwUrlPathLength + urlComp.dwExtraInfoLength);
urlPath[urlComp.dwUrlPathLength + urlComp.dwExtraInfoLength] = 0;
/* Use WinHttpOpen to obtain a session handle. */
hSession = WinHttpOpen(L"Perl",
WINHTTP_ACCESS_TYPE_NO_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0);
}
/* Specify an HTTP server. */
if (hSession)
hConnect = WinHttpConnect(hSession,
hostName,
urlComp.nPort,
0);
/* Create an HTTP request handle. */
if (hConnect)
hRequest = WinHttpOpenRequest(hConnect,
L"GET",
urlPath,
NULL,
WINHTTP_NO_REFERER,
acceptTypes,
urlComp.nScheme == INTERNET_SCHEME_HTTPS
? WINHTTP_FLAG_SECURE
: 0);
/* If specified, disable certificate-related errors for https connections. */
if (hRequest
&& bIgnoreCertErrors
&& urlComp.nScheme == INTERNET_SCHEME_HTTPS) {
DWORD secFlags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID
| SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
| SECURITY_FLAG_IGNORE_UNKNOWN_CA
| SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
if(!WinHttpSetOption(hRequest,
WINHTTP_OPTION_SECURITY_FLAGS,
&secFlags,
sizeof(secFlags))) {
bAborted = TRUE;
}
}
/* Call WinHttpGetProxyForUrl with our target URL. If auto-proxy succeeds,
* then set the proxy info on the request handle. If auto-proxy fails,
* ignore the error and attempt to send the HTTP request directly to the
* target server (using the default WINHTTP_ACCESS_TYPE_NO_PROXY
* configuration, which the request handle will inherit from the session).
*/
if (hRequest && !bAborted) {
WINHTTP_AUTOPROXY_OPTIONS AutoProxyOptions;
WINHTTP_PROXY_INFO ProxyInfo;
DWORD cbProxyInfoSize = sizeof(ProxyInfo);
ZeroMemory(&AutoProxyOptions, sizeof(AutoProxyOptions));
ZeroMemory(&ProxyInfo, sizeof(ProxyInfo));
AutoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
AutoProxyOptions.dwAutoDetectFlags =
WINHTTP_AUTO_DETECT_TYPE_DHCP |
WINHTTP_AUTO_DETECT_TYPE_DNS_A;
AutoProxyOptions.fAutoLogonIfChallenged = TRUE;
if(WinHttpGetProxyForUrl(hSession,
url,
&AutoProxyOptions,
&ProxyInfo)) {
if(!WinHttpSetOption(hRequest,
WINHTTP_OPTION_PROXY,
&ProxyInfo,
cbProxyInfoSize)) {
bAborted = TRUE;
Perl_warn(aTHX_ "Win32::HttpGetFile: setting proxy options failed");
}
Safefree(ProxyInfo.lpszProxy);
Safefree(ProxyInfo.lpszProxyBypass);
}
}
/* Send a request. */
if (hRequest && !bAborted)
bResults = WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA,
0,
0,
0);
/* End the request. */
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);
/* Retrieve HTTP status code. */
if (bResults) {
dwQuerySize = sizeof(dwHttpStatusCode);
bResults = WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
WINHTTP_HEADER_NAME_BY_INDEX,
&dwHttpStatusCode,
&dwQuerySize,
WINHTTP_NO_HEADER_INDEX);
}
/* Retrieve HTTP status text. Note this may be a success message. */
if (bResults) {
dwQuerySize = ONE_K_BUFSIZE * 2 - 2;
ZeroMemory(&msgbuf, ONE_K_BUFSIZE * 2);
bResults = WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_STATUS_TEXT,
WINHTTP_HEADER_NAME_BY_INDEX,
msgbuf,
&dwQuerySize,
( run in 4.114 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )