View Single Post
  #9 (permalink)  
Old 05-23-2008, 12:55 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Streaming in PHP

Making a POST request to an https server

PHP Code:
<?php
/* Send POST request to https://secure.example.com/form_action.php
 * Include form elements named "foo" and "bar" with dummy values
 */

$sock fsockopen("ssl://secure.example.com"443$errno$errstr30);
if (!
$sock) die("$errstr ($errno)\n");

$data "foo=" urlencode("Value for Foo") . "&bar=" urlencode("Value for Bar");

fwrite($sock"POST /form_action.php HTTP/1.0\r\n");
fwrite($sock"Host: secure.example.com\r\n");
fwrite($sock"Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock"Content-length: " strlen($data) . "\r\n");
fwrite($sock"Accept: */*\r\n");
fwrite($sock"\r\n");
fwrite($sock"$data\r\n");
fwrite($sock"\r\n");

$headers "";
while (
$str trim(fgets($sock4096)))
  
$headers .= "$str\n";

echo 
"\n";

$body "";
while (!
feof($sock))
  
$body .= fgets($sock4096);

fclose($sock);
?>
__________________
With,
J. Jeyaseelan

Everything Possible
Reply With Quote