I'm writing a C++ server client that's POSTing and GETting data from a server on an RPi. It's sending and receiving a string of information since that's what C++ can handle, however WinHttpWriteData returns an error of 87
, which I believe is ERROR_INVALID_PARAMETER.
What prints out from GetLastError():
Failed to write HTTP data (WinHttpWriteData): 87
I'm using the the Windows docs as a reference (https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpwritedata) to make sure that I've got it set up correctly, but their string is about as long as the one I'm using. If I change the parameter dwNumberOfBytesToWrite
to 8, it sends. Do I have to change my code to loop through sections of 8 or less to send? No matter the length of the string I'm sending, the server prints a 400
error.
The server's running python's flask if that helps. I know that I can connect to the server GET data without issue.
Any help or insight is much appreciated, thank you!
Code:
bool webClient::postDevices(char* i_buffer)
{
bool l_results = true;
DWORD l_bytesWritten = 0;
if (request(MIXER_IP_ADDR, L"POST", L"devices"))
{
// Send the POST request
if (!WinHttpSendRequest(m_httpRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA,
0,
sizeof(i_buffer),
0))
{
std::cout << "Failed to send HTTP Request (WinHttpSendRequest): " << GetLastError() << std::endl;
l_results = false;
goto end_request;
}
// Write data to the server.
if (!WinHttpWriteData(m_httpRequest,
i_buffer,
(DWORD)strlen(i_buffer),
&l_bytesWritten))
{
std::cout << "Failed to write HTTP data (WinHttpWriteData): " << GetLastError() << std::endl;
l_results = false;
goto end_request;
}
// End the request.
if (!WinHttpReceiveResponse(m_httpRequest, NULL))
{
std::cout << "Failed to end HTTP request (WinHttpReceiveRequest): " << GetLastError() << std::endl;
l_results = false;
goto end_request;
}
}
end_request:
closeConnection();
return l_results;
}