Amazon MWS in C++ by WinHTTP

Clash Royale CLAN TAG#URR8PPP
Amazon MWS in C++ by WinHTTP
I try to read reports from Amazon MWS
wchar_t szUrl[500];
swprintf_s( szUrl, sizeof(szUrl)/sizeof(szUrl[0]), L"/?AWSAccessKeyId=%s"
L"&Action=GetReportRequestList"
L"&Merchant=%s"
L"&MWSAuthToken=%s"
L"&SignatureVersion=2"
L"&Timestamp=%.4d-%.2d-%.2dT%.2d%%3A%.2d%%3A%.2dZ"
L"&Version=2009-01-01"
L"&Signature=%s"
L"&SignatureMethod=HmacSHA256"
L"&MaxCount=2",
AmazonMWS::GetInstance().GetAccessKey(), AmazonMWS::GetInstance().GetSellerID(),
AmazonMWS::GetInstance().GetAuthToken(), sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond,
signature);
CString strUrl( szUrl);
strUrl.Replace( L"=", L"%3D");
I use WinHTTP:
m_hSession= WinHttpOpen(...
m_hConnect = WinHttpConnect( m_hSession, L"mws-eu.amazonservices.com",...
HINTERNET hRequest = WinHttpOpenRequest( m_hConnect, L"POST,(LPCWSTR)strUrl,...
If I just send this request:
WinHttpSendRequest( hRequest, NULL, 0, NULL..
Amazon returns a XML file with the error 'Either Action or Operation query parameter must be present.'
If I try to send header information, 'HTTP/1.1nContent-Type....'
and integrate this in WinHttpSendRequest
WinHttpSendRequest( hRequest, (LPCWSTR)header, header.GetLength(), NULL, 0,....
The call to WinHttpSendRequest fails and getLastError returns 87, WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH was used.
Did one of you got MWS to run with WinHTTP?
Many thanks for your help.
Solved the first point. WinHTTPSendRequest is very strict on the parameters.
WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, "Blan", 4, 4, 0);
That works, Optional data is send.
WinHttpSendRequest( hRequest, L"Blan", 4, WINHTTP_NO_REQUEST_DATA, 0, 4, 0);
That doesn't work. The header is unknown/not standard/whatever.
WinHttpSendRequest( hRequest, L"Content-Type: application/x-www-form-urlencoded", -1L, WINHTTP_NO_REQUEST_DATA, 0, 4, 0);
That works, header is good.
WinHttpSendRequest( hRequest, L"Content-Type: application/x-www-form-urlencoded", -1L, "Blan", 4, 4, 0);
That works, header is OK, data is send. The parameter dwTotalLength seems to be for multi-part requests. So here only the length of the optional data.
The length of the header MUST NOT BE ADDED.
It seems that WinHTTPSendRequest parses/anlyses the header. Really?
Or the server returns an error leading to GetLastError() == 87?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.