WinHttp的::WinHttpWriteData,GetLastError返回87(参数错误),求解

矫情狗_____ 2013-06-16 04:24:31
this->m_hRequest = ::WinHttpOpenRequest(this->m_hConnect, L"POST", L"/login", nullptr, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
if(!this->m_hRequest)
return false;

bRequest = ::WinHttpAddRequestHeaders(this->m_hRequest, L"Host: www.dropbox.com", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if(!bRequest) false;

bRequest = ::WinHttpAddRequestHeaders(this->m_hRequest, L"Connection: keep-alive", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if(!bRequest) false;

bRequest = ::WinHttpAddRequestHeaders(this->m_hRequest, L"Accept: text/html, application/xhtml+xml, */*", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if(!bRequest) return false;

bRequest = ::WinHttpAddRequestHeaders(this->m_hRequest, L"Accept-Encoding: gzip, deflate", (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if(!bRequest) return false;

bRequest = ::WinHttpAddRequestHeaders(this->m_hRequest, this->_char2wchar(this->m_sCookie).c_str(), (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD);
if(!bRequest) return false;

bRequest = ::WinHttpSendRequest(this->m_hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
if(!bRequest) return false;

char psPost[1024] = {0};
sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken);

DWORD dwByWritten = 0;
bRequest = ::WinHttpWriteData(this->m_hRequest, psPost, strlen(psPost), &dwByWritten);
DWORD nError = ::GetLastError(); //返回值为87

//求解到底哪里参数错误了...
...全文
409 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
有新工作否 2013-06-17
  • 打赏
  • 举报
回复
那就是验证有问题了呗,我以为你做实验,搞自己的网站呢。通不过很正常。
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
引用 10 楼 yudahai109 的回复:
[quote=引用 7 楼 stacksg 的回复:] [quote=引用 6 楼 yudahai109 的回复:] [quote=引用 2 楼 stacksg 的回复:] [quote=引用 1 楼 yudahai109 的回复:] 楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
我只是需要一步出错就放弃这个操作嘛[/quote] 晕死,当然需要了,一步出错,就结束程序呀,莫非你还让他继续运行不成?也不利于你检查错误呀。你每步都检查一下,然后单步执行,一下子就找到错误了。[/quote] 问题不在那,先不说return,那都是小事,我只是做测试.现在问题是WinHttpWriteData这个问题,这个接口返回FALSE,并且DWORD nerr = ::GetLastError(); nerr == 87; //代表参数错误.[/quote] (DWORD)strlen(psPost)转换一下试试,前面的都要转换。其他的我也想不到了。 但你最好把

char psPost[1024] = {0};
sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken);
放在开头,然后把WinHttpSendRequest的参数修改一下,

WinHttpSendRequest(this->m_hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, (DWORD)strlen(psPost), 0)
因为我怀疑你WinHttpSendRequest和WinHttpWriteData的参数不一致导致的问题。你先这样做试试。 [/quote] 现在我把POST正文直接放到WinHttpSendRequest这里来了。但是引起了403。坑爹
有新工作否 2013-06-16
  • 打赏
  • 举报
回复
引用 7 楼 stacksg 的回复:
[quote=引用 6 楼 yudahai109 的回复:] [quote=引用 2 楼 stacksg 的回复:] [quote=引用 1 楼 yudahai109 的回复:] 楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
我只是需要一步出错就放弃这个操作嘛[/quote] 晕死,当然需要了,一步出错,就结束程序呀,莫非你还让他继续运行不成?也不利于你检查错误呀。你每步都检查一下,然后单步执行,一下子就找到错误了。[/quote] 问题不在那,先不说return,那都是小事,我只是做测试.现在问题是WinHttpWriteData这个问题,这个接口返回FALSE,并且DWORD nerr = ::GetLastError(); nerr == 87; //代表参数错误.[/quote] (DWORD)strlen(psPost)转换一下试试,前面的都要转换。其他的我也想不到了。 但你最好把

char psPost[1024] = {0};
sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken);
放在开头,然后把WinHttpSendRequest的参数修改一下,

WinHttpSendRequest(this->m_hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, (DWORD)strlen(psPost), 0)
因为我怀疑你WinHttpSendRequest和WinHttpWriteData的参数不一致导致的问题。你先这样做试试。
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
引用 8 楼 henry3695 的回复:
引用 5 楼 stacksg 的回复:
那个是宽字符... [quote=引用 4 楼 henry3695 的回复:] 编码是不是有问题啊,把字符串前面的L去掉,是多字节编码吧
用多字节试试[/quote] 哥们,不是那里的问题,懂?
我看你有戏 2013-06-16
  • 打赏
  • 举报
回复
引用 5 楼 stacksg 的回复:
那个是宽字符...
引用 4 楼 henry3695 的回复:
编码是不是有问题啊,把字符串前面的L去掉,是多字节编码吧
用多字节试试
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
引用 6 楼 yudahai109 的回复:
[quote=引用 2 楼 stacksg 的回复:] [quote=引用 1 楼 yudahai109 的回复:] 楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
我只是需要一步出错就放弃这个操作嘛[/quote] 晕死,当然需要了,一步出错,就结束程序呀,莫非你还让他继续运行不成?也不利于你检查错误呀。你每步都检查一下,然后单步执行,一下子就找到错误了。[/quote] 问题不在那,先不说return,那都是小事,我只是做测试.现在问题是WinHttpWriteData这个问题,这个接口返回FALSE,并且DWORD nerr = ::GetLastError(); nerr == 87; //代表参数错误.
有新工作否 2013-06-16
  • 打赏
  • 举报
回复
引用 2 楼 stacksg 的回复:
[quote=引用 1 楼 yudahai109 的回复:] 楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
我只是需要一步出错就放弃这个操作嘛[/quote] 晕死,当然需要了,一步出错,就结束程序呀,莫非你还让他继续运行不成?也不利于你检查错误呀。你每步都检查一下,然后单步执行,一下子就找到错误了。
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
那个是宽字符...
引用 4 楼 henry3695 的回复:
编码是不是有问题啊,把字符串前面的L去掉,是多字节编码吧
我看你有戏 2013-06-16
  • 打赏
  • 举报
回复
编码是不是有问题啊,把字符串前面的L去掉,是多字节编码吧
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
引用 1 楼 yudahai109 的回复:
楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
而且申请栈内存前后没区别,因为我的token并没有再一次获取
矫情狗_____ 2013-06-16
  • 打赏
  • 举报
回复
引用 1 楼 yudahai109 的回复:
楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.
我只是需要一步出错就放弃这个操作嘛
有新工作否 2013-06-16
  • 打赏
  • 举报
回复
楼主,你的代码写的有问题呀,if(!bRequest) return false;????如果非真,应该直接结束程序吧,你这么多return false有什么用?非真,直接跳出程序,就知道哪一步错了。 看看微软给的例子 http://msdn.microsoft.com/en-us/library/windows/desktop/aa384120(v=vs.85).aspx 貌似这句 char psPost[1024] = {0}; sprintf(psPost, "t=%&lhs_type=default&display=desktop&login_email=1626086788@qq.com&login_password=********&login_submit=1&login_submit_dummy=%E7%99%BB%E5%BD%95", this->m_sToken); 应该放在WinHttpSendRequest 这个函数之前,不能为0噢。 看看微软的解释 dwTotalLength [in] An unsigned long integer value that contains the length, in bytes, of the total data sent. This parameter specifies the Content-Length header of the request. If the value of this parameter is greater than the length specified by dwOptionalLength, then WinHttpWriteData can be used to send additional data. dwTotalLength must not change between calls to WinHttpSendRequest for the same request. If dwTotalLength needs to be changed, the caller should create a new request.

65,184

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧