Thread: POSTing to a PHP script

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    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?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >>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?

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    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.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 12:27 AM
  2. PHP script to c++
    By smaakage in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 11-06-2005, 01:11 PM
  3. php mysql cprogramming posting issue
    By xddxogm3 in forum Tech Board
    Replies: 5
    Last Post: 03-22-2004, 03:32 PM
  4. php script question (is this possible?)
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-30-2003, 09:20 PM
  5. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM