1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#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,
"Content-type: application/x-www-form-urlencoded",
-1, // this calculates the strlen
(char*)postData,
dataLen
);
if( !res )
{
printf("Unable to send request. Error %ld\n", GetLastError());
exit(1);
}
printf("Request sent\n");
return 0;
}
|