2
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());
}

这个 WinHttpCrackUrl api 在 Win7(操作系统)上失败,出现 87(无效参数)请任何人提出解决方案,或者我如何在服务器端以简单的方式解码我的 URL?我也想知道如何区分 %20 和编码URL 和 URL 中存在的实际数据。示例:localhost:8080\Server\search?value="value%20"

4

1 回答 1

0

将所需的组件长度设置为预期值。

如果不需要破解,全部归零。

urlComp.dwSchemeLength    = (DWORD)0;
urlComp.dwHostNameLength  = (DWORD)0;
urlComp.dwUrlPathLength   = (DWORD)0;
urlComp.dwExtraInfoLength = (DWORD)0;

或者

std::wstring urlHost;
urlHost.resize(url.size());

urlComp.dwHostNameLength = (DWORD)urlHost.size();
urlComp.lpszHostName = &urlHost[0];
于 2021-05-07T08:21:37.943 回答