crack:裂缝
C++
BOOL WINAPI WinHttpCrackUrl(
In LPCWSTR pwszUrl,
In DWORD dwUrlLength,
In DWORD dwFlags,
Inout LPURL_COMPONENTS lpUrlComponents
);
参数解释:
pwszUrl [in]
Pointer to a string that contains the canonical URL to separate. WinHttpCrackUrl does not check this URL for validity or correct format before attempting to crack it.
dwUrlLength [in]
The length of the pwszUrl string, in characters. If dwUrlLength is set to zero, WinHttpCrackUrl assumes that the pwszUrl string is null terminated and determines the length of the pwszUrl string based on that assumption.
dwFlags [in]
The flags that control the operation. This parameter can be one of the following values.
这个函数的作用:
The WinHttpCrackUrl function separates a URL into its component parts such as host name and path.
例子:
URL_COMPONENTS urlComp;
LPCWSTR pwszUrl1 =
L"http://search.msn.com/results.asp?RS=CHECKED&FORM=MSNH&v=1&q=wininet";
DWORD dwUrlLen = 0;
// Initialize the URL_COMPONENTS structure.
ZeroMemory(&urlComp, sizeof(urlComp));
urlComp.dwStructSize = sizeof(urlComp);
// Set required component lengths to non-zero
// so that they are cracked.
urlComp.dwSchemeLength = (DWORD)-1;
urlComp.dwHostNameLength = (DWORD)-1;
urlComp.dwUrlPathLength = (DWORD)-1;
urlComp.dwExtraInfoLength = (DWORD)-1;
// Crack the URL.
if (!WinHttpCrackUrl( pwszUrl1, (DWORD)wcslen(pwszUrl1), 0, &urlComp))
{
printf("Error %u in WinHttpCrackUrl.\n", GetLastError());
}
else
{
// Change the search information.
// New info is the same length.
urlComp.lpszExtraInfo = L"?RS=CHECKED&FORM=MSNH&v=1&q=winhttp";
// Obtain the size of the new URL and allocate memory.
WinHttpCreateUrl( &urlComp, 0, NULL, &dwUrlLen);
LPWSTR pwszUrl2 = new WCHAR[dwUrlLen];
// Create a new URL.
if(!WinHttpCreateUrl( &urlComp, 0, pwszUrl2, &dwUrlLen))
{
printf("Error %u in WinHttpCreateUrl.\n", GetLastError());
}
else
{
// Show both URLs.
printf("Old URL: %S\nNew URL: %S\n", pwszUrl1, pwszUrl2);
}
// Free allocated memory.
delete [] pwszUrl2;
}