【问题标题】:WinHttpCrackUrl failed with 87 errorWinHttpCrackUrl 失败,出现 87 错误
【发布时间】:2013-08-06 09:53:59
【问题描述】:
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(invalid param) 失败,请任何人提出解决方案,或者我如何在服务器端以简单的方式解码我的 URL?我也想知道如何区分 % 20 来自编码的 URL 和 URL 中存在的实际数据。示例:localhost:8080\Server\search?value="value%20"

【问题讨论】:

  • 引用:“这个 WinHttpCrackUrl api 失败了”然后这句话就停止了,你寻求解决方案。它失败的原因是什么?
  • 查看官方error reference会发现错误87ERROR_INVALID_PARAMETER(“参数不正确。”)。所以函数的参数之一是不正确的。
  • 代码 sn-p 运行良好,也许您在实际场景中有不同(无效)的参数。
  • 没有我在 Windows 7 的应用程序中使用相同的代码。另外我想知道如何将 %20 与编码的 URL 和 URL 中存在的实际数据区分开来。示例:localhost:8080\Server\search?value="value%20"
  • 假设 WinHttpOpen 在这段代码之前的某个地方被调用是否公平?

标签: c++ http


【解决方案1】:

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

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

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];

【讨论】:

  • 感谢您的帖子!如果你能用简单的语言添加这段代码的作用(也许是 API 的链接?)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-20
  • 1970-01-01
  • 2013-04-11
  • 2017-08-14
  • 2011-09-01
  • 2018-02-24
相关资源
最近更新 更多