1. <?php
  2. // Making a POST request to an https server
  3. // URL: http://us3.php.net/stream#id6769950
  4.  
  5. /* Send POST request to https://secure.example.com/form_action.php
  6.  * Include form elements named "foo" and "bar" with dummy values
  7.  */
  8.  
  9. $sock = fsockopen("ssl://secure.example.com", 443, $errno, $errstr, 30);
  10. if (!$sock) die("$errstr ($errno)\n");
  11.  
  12. $data = "foo=" . urlencode("Value for Foo") . "&bar=" . urlencode("Value for Bar");
  13.  
  14. fwrite($sock, "POST /form_action.php HTTP/1.0\r\n");
  15. fwrite($sock, "Host: secure.example.com\r\n");
  16. fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
  17. fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
  18. fwrite($sock, "Accept: */*\r\n");
  19. fwrite($sock, "\r\n");
  20. fwrite($sock, "$data\r\n");
  21. fwrite($sock, "\r\n");
  22.  
  23. $headers = "";
  24. while ($str = trim(fgets($sock, 4096)))
  25. $headers .= "$str\n";
  26.  
  27. echo "\n";
  28.  
  29. $body = "";
  30. while (!feof($sock))
  31. $body .= fgets($sock, 4096);
  32.  
  33. fclose($sock);
  34. ?>