The following code
fRequestHandle = HttpOpenRequestA(
fConnectHandle,
\"POST\", url.c_str(),
NULL,
After some digging I was getting error 122 when an AV or firewall blocked my GET request.
EDIT:
Looks like this guy had the same problem, the URL is too long.
http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/68612c89-bbce-4d88-926d-5d76771be944
In general, your url should be 2k or less in size. Since you are performing a POST, you are heading in the right direction, its just that for the bulk of your data, you want to pass that as the body of the HTTP request like in this example:
POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme <--You need to do this!
Cribbed from here: http://developers.sun.com/mobility/midp/ttips/HTTPPost/
Here's what I was thinking you would want to do:
std::string url("http://host.com/url");
std::string dataPayload("name=value&othername=anothervalue");//Query string payload style.
DWORD dataPayloadLength = dataPayload.length();
std::ostringstream headerStream;
headerStream << "content-length: ";
headerStream << dataPayloadLength;
std::string headers = headerStream.str();
DWORD headerLength = headers.length();
HINTERNET handle = HttpOpenRequest(hConnect,
"POST",
url.c_str(),
NULL, NULL, NULL,
INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
0);
if(!handle) {
DWORD errorCode = GetLastError();
//Handle error here.
}
//Use this thing to send POST values.
if(! HttpSendRequest(handle,
headers.c_str(),
headerLength,
dataPayload, //lpOptional <--Your POST data...not really optional for you.
dataPayloadLength) {
DWORD errorCode = GetLastError();
//Handle error here.
}