#define _WIN32_WINNT 0x600 #include <stdio.h> #include <wininet.h> #define BUFLEN 200 static const char *acceptTypes[] = {"application/x-www-form-urlencoded", NULL}; static const char *postData = "teststr=Hello+world&testval=42"; int main() { HINTERNET hSession, hConnect, hFile; if( ( hSession = InternetOpen( "myapp", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ) ) == NULL ) { printf("Couldn't start session. Error %ld\n", GetLastError()); exit(1); } printf("Session started\n"); if( ( hConnect = InternetConnect( hSession, "localhost", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ) ) == NULL ) { printf("Unable to connect to server. Error %ld\n", GetLastError()); exit(1); } printf("Connected to server\n"); if( ( hFile = HttpOpenRequest( hConnect, "POST", "/test/index.php", NULL, NULL, acceptTypes, INTERNET_FLAG_RELOAD, 0 ) ) == NULL ) { printf("Unable to open request. Error %ld\n", GetLastError()); exit(1); } printf("Opening request..Opened\n"); unsigned long dataLen = strlen(postData)+1; bool res = HttpSendRequest( hFile, NULL, 0, (char*)postData, dataLen ); if( !res ) { printf("Unable to send request. Error %ld\n", GetLastError()); exit(1); } printf("Request sent\n"); return 0; }
<?php if( isset($_POST['teststr']) ) echo $_POST['teststr']; ?>
char headers[] = "Content-Type: application/x-www-form-urlencoded\r\n";
bool res = HttpSendRequest(hFile, headers, sizeof headers, (char*)postData, dataLen);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)