-
POSTing to a PHP script
I'm having trouble POSTing variables to a PHP script using WinInet. Here is the code:
Code:
hRequest=HttpOpenRequest(hConnect, "POST", "printpostvariables.php" ,
NULL , NULL, NULL, NULL , NULL );
lstrcpy(lpTempBuffer,"message='hello world'&s='2'");
HttpSendRequest(hRequest,NULL,NULL,lpTempBuffer, lstrlen(lpTempBuffer) );
The return codes from the functions are all good. However, in printpostvariables.php, which WILL print any variables sent to it by the POST command, it cannot find the 'message' or 's' variables. Is the format of my buffer incorrect? If not, what IS happening?
-
>>optional data to be sent immediately after the request headers.<<
I'm guessing you have to add the intervening new lines yourself.
Code:
lstrcpy(lpTempBuffer,"\r\n\r\nmessage='hello world'&s='2'");
...or maybe one set or maybe \n\n...
If not, can you get the php page to dump the headers in raw format so you can see exactly what is being sent?
-
It worked! I found some PHP script code that used the POST command to post to ANOTHER PHP script, and I basically copied their headers and included them. Here is the code:
Code:
lpHeaders[0]=0;
lstrcat(lpHeaders,"Accept: */*\r\n
lstrcat(lpHeaders,"Accept-Language: en-au\r\n
lstrcat(lpHeaders,"Content-Type: application/x-www-form-urlencoded\r\n
lstrcat(lpHeaders,"User-Agent: BenNet\r\n
lstrcat(lpHeaders,"Connection: Keep-Alive\r\n
lstrcat(lpHeaders,"Cache-Control: no-cache\r\n\r\n");
lstrcpy(lpTempBuffer,"message=helloworld&s=2");
That CProg interface will be up and running in no time. Thanks for the help.