You are here: Re: php https/http get/post class « All PHP « IT news, forums, messages
Re: php https/http get/post class

Posted by NC on 09/28/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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация