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(OS)上失败了87(无效参数)请任何人建议解决方案或如何在服务器端轻松解码我的URL?。我也想知道如何区分% 20来自URL中的编码URL和实际数据。示例:localhost:8080 \ Server \ search?value =“value%20”
答案 0 :(得分: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];