我在异步模式下通过 WinHttpSendRequest 发送 POST 数据时遇到问题。
在同步模式下:
WinHttpAddRequestHeaders(request_handles.at(handler_index), L"Content-Type:application/x-www-form-urlencoded", -1L, WINHTTP_ADDREQ_FLAG_ADD);
int rc = WinHttpSendRequest(request_handles.at(handler_index), WINHTTP_NO_ADDITIONAL_HEADERS, 0, (LPVOID)postData.c_str(), dataLen, dataLen, 0);
奇迹般有效。我的服务器得到了我期望的 postData。
在异步模式下:
WINHTTP_STATUS_CALLBACK cb = WinHttpSetStatusCallback(request_handles.at(handler_index), httpReadCallback, WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE | WINHTTP_CALLBACK_STATUS_REQUEST_ERROR |
WINHTTP_CALLBACK_STATUS_REDIRECT | WINHTTP_CALLBACK_STATUS_SECURE_FAILURE | WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE |
WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION | WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, NULL);
WinHttpAddRequestHeaders(request_handles.at(handler_index), L"Content-Type:application/x-www-form-urlencoded", -1L, WINHTTP_ADDREQ_FLAG_ADD);
int rc = WinHttpSendRequest(request_handles.at(handler_index), WINHTTP_NO_ADDITIONAL_HEADERS, 0, (LPVOID)postData.c_str(), dataLen, dataLen, 0);
服务器收到一个 POST 请求,但没有数据主体。是什么赋予了?