首页 > 解决方案 > Windows WinHTTP (C++ API) WinHttpSetCredentials 与非 ascii(实际上是非 Windows-1252)错误 87

问题描述

我正在尝试将 WinHTTP 库与基本身份验证一起使用。我正在测试用户名或密码具有“特殊”字符的情况(即,不在 Windows-1252 中)并且我似乎无法使用 WinHttpSetCredentials 设置凭据

结果是错误,代码为 87(“参数不正确”)

Windows-1252 意义上的“扩展 ascii”(128~255)将起作用。

我已经嗅探了标题,似乎 WinHTTP 在 Windows-1252 中重新编码了我的用户/密码。

我的调用看起来像这样,当 user 或 pass 有非 Win1252 字符时它返回 false。

::WinHttpSetCredentials(requestHdl, dwTarget, m_authScheme /*basic*/,
     user.c_str() /*wstring in UCS2*/,
     pass.c_str(), /*wstring in UCS2*/ 
     NULL /*reserved?*/)

关于为什么此调用不正确支持一般 wstring 字符的任何建议?我在文档中找不到任何东西(除了一个关于假设数据是 ASCII 的奇怪标志......)。

标签: c++windowshttpcharacter-encodingwinhttp

解决方案


推荐阅读