Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Construct HTTP POST 1

Status
Not open for further replies.

Sleidia

Technical User
Joined
May 4, 2001
Messages
1,284
Location
FR
Hello,

Does someone know how to construct a HTTP POST?
I can't find any example about that.

Many thanks!
 

Thanks for this precious link, but I would like to see practical examples made with PHP.

Thanks.
 
This should work:
[tt]$post_data = "variable1=yes&variable2=no";
$socket = fsockopen(&quot;<hostname>&quot;, 80);
fwrite($socket, &quot;POST <uri> HTTP/1.1\r\n&quot;);
fwrite($socket, &quot;Host: <hostname>\r\n&quot;);
fwrite($socket, &quot;Content-Length: &quot; . strlen($post_data) . &quot;\r\n&quot;);
fwrite($socket, &quot;\r\n&quot; . $post_data);
while (($response .= fread($socket, 1024)) === &quot;&quot;)
;
fclose($fp);[/tt]

//Daniel
 
And of course the [tt]fclose($fp);[/tt] should be [tt]fclose($socket);[/tt]

//Daniel
 
Thanks a lot Daniel,

I'm gonna study that seriously.

Have a nice day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top