May 11, 2003 #1 Sleidia Technical User May 4, 2001 1,284 FR Hello, Does someone know how to construct a HTTP POST? I can't find any example about that. Many thanks!
Hello, Does someone know how to construct a HTTP POST? I can't find any example about that. Many thanks!
May 11, 2003 1 #2 danielhozac Programmer Aug 21, 2001 2,058 SE Have you read the HTTP RFC? http://www.ietf.org/rfc/rfc2068.txt //Daniel Upvote 0 Downvote
May 12, 2003 Thread starter #3 Sleidia Technical User May 4, 2001 1,284 FR Thanks for this precious link, but I would like to see practical examples made with PHP. Thanks. Upvote 0 Downvote
May 12, 2003 #4 danielhozac Programmer Aug 21, 2001 2,058 SE This should work: [tt]$post_data = "variable1=yes&variable2=no"; $socket = fsockopen("<hostname>", 80); fwrite($socket, "POST <uri> HTTP/1.1\r\n" fwrite($socket, "Host: <hostname>\r\n" fwrite($socket, "Content-Length: " . strlen($post_data) . "\r\n" fwrite($socket, "\r\n" . $post_data); while (($response .= fread($socket, 1024)) === "" ; fclose($fp);[/tt] //Daniel Upvote 0 Downvote
This should work: [tt]$post_data = "variable1=yes&variable2=no"; $socket = fsockopen("<hostname>", 80); fwrite($socket, "POST <uri> HTTP/1.1\r\n" fwrite($socket, "Host: <hostname>\r\n" fwrite($socket, "Content-Length: " . strlen($post_data) . "\r\n" fwrite($socket, "\r\n" . $post_data); while (($response .= fread($socket, 1024)) === "" ; fclose($fp);[/tt] //Daniel
May 12, 2003 #5 danielhozac Programmer Aug 21, 2001 2,058 SE And of course the [tt]fclose($fp);[/tt] should be [tt]fclose($socket);[/tt] //Daniel Upvote 0 Downvote
May 12, 2003 Thread starter #6 Sleidia Technical User May 4, 2001 1,284 FR Thanks a lot Daniel, I'm gonna study that seriously. Have a nice day. Upvote 0 Downvote