我尝试使用WinHttpSendRequest从服务器下载文件,但结果是0,错误代码是87 (ERROR_INVALID_PARAMETER)。
// Specify an HTTP server.
if (hSession)
hConnect = WinHttpConnect( hSession, T2W((LPTSTR)tsDownloadServer.c_str()), wPort, 0 );
// tsDownloadServer = "xxx.xxx.xxx.xx:xxxx"
// Create an HTTP request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET",T2W((LPTSTR)tsDownloadFileURLPath.c_str()), NULL, WINHTTP_NO_REFERER, ppwszAcceptTypes, dwOpenRequestFlag );
// tsDownloadFileURLPath = "/xxxxx/xxxxxxxx/58bbf9067ad35634c7caa5594e8ec712/windows_installer/xxxxx_xxxxxx.wak"
bResults = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0 );
bResults为0,GetLastError()返回87
我在网上研究了相关问题是由于超过24字节的数据,但在我的情况下,我在参数中设置了WINHTTP_NO_REQUEST_DATA。
如何向服务器发送请求?
发布于 2019-04-02 09:54:43
ERROR_INVALID_PARAMETER
表示问题出在处理程序hRequest
上,您还没有检查返回值。如果为NULL,则可能是上一次调用WinHttpOpenRequest
时的原因;或者甚至是WinHttpConnect
失败了,所以它不再获取hRequest
。
正如@Remy Lebeau所说,这取决于您的Unicode设置。禁用Unicode时,如果tsDownloadServer
和tsDownloadFileURLPath
的类型为wstring
,则(LPTSTR)tsDownloadServer.c_str()
将从宽字符转换为多个字节。则宽字符中的零(如果字符为ASCII)被视为终止符:
并且字符串被截断:
https://stackoverflow.com/questions/55459862
复制相似问题