|  | Posted by NC on 06/13/92 11:57 
lallous wrote:>
 > Can anyone suggest a free and CURL-free HTTPS and HTTP
 > GET/POST PHP classes?
 
 Why?  GET can be done in one line:
 
 $content =
 file_get_contents('https://remoteserver.com/path/script.php?name=value');
 
 POST is a little more complicated, but once you learn how to send POST
 headers and read HTTP(S) resposes, it gets really easy:
 
 $content = '';
 $flag = false;
 $post_query = 'a=1&b=2'; // name-value pairs
 $post_query = urlencode($post_query) . "\r\n";
 $host = 'www.somehost.com';
 $path = 'path/to/some/script.php';
 $fp = fsockopen($host, '80');
 // This is plain HTTP; for HTTPS, use
 // $fp = fsockopen($host, '443');
 if ($fp) {
 fputs($fp, "POST $path HTTP/1.0\r\n");
 fputs($fp, "Host: $host\r\n");
 fputs($fp, "Content-length: ". strlen($post_query) ."\r\n\r\n");
 fputs($fp, $post_query);
 while (!feof($fp)) {
 $line = fgets($fp, 10240);
 if ($flag) {
 $content .= $line;
 } else {
 $headers .= $line;
 if (strlen(trim($line)) == 0) {
 $flag = true;
 }
 }
 }
 fclose($fp);
 }
 
 Now $headers contains HTTP headers returned by the remote server, while
 $content contains the body of the response (the document you are trying
 to retrieve).
 
 Cheers,
 MC
  Navigation: [Reply to this message] |