I'm trying to post data to a test .php script using XAMPP on my local machine, but it always fails with ERROR_HTTP_HEADER_NOT_FOUND. I check the server logs and no request was sent to Apache. I can manually do it via a web browser and the php script runs as expected.
Here's the C++ code that doesn't work. Can someone point out the problem?
static const char *accepttypes[]={ "application/x-www-form-urlencoded", NULL};
static const char headers[]="application/x-www-form-urlencoded\r\n";
// open session
HINTERNET hsession;
if ((hsession=InternetOpen(_T("Whatever"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)) != NULL) {
HINTERNET hconnect;
if ((hconnect=InternetConnect(hsession, _T("127.0.0.1"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0)) != NULL) {
HINTERNET hpostreq;
if ((hpostreq=HttpOpenRequestA(hconnect, "POST", "/mytest.php", NULL, NULL, accepttypes, INTERNET_FLAG_RELOAD, 0)) != NULL) {
BYTE *data=(BYTE*)"xyz=1234";
DWORD datasize=8;
if (HttpSendRequestA(hpostreq, headers, sizeof(headers), (LPVOID) data, datasize)) {
....
// ^^^^^ That always fails with ERROR_HTTP_HEADER_NOT_FOUND