Mombu the Php Forum

Mombu the Php Forum > Php > php https/http get/post class
REGISTER NOW! Search Today's Posts Mark Forums Read




Reply
 
Thread Tools Search this Thread Display Modes
1 10th November 09:42
lallous
External User
 
Posts: 1
Default php https/http get/post class



Hello

Can anyone suggest a free and CURL-free HTTPS and HTTP GET/POST PHP classes?

Regards,
Elias
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


2 10th November 14:12
nc
External User
 
Posts: 1
Default php https/http get/post class



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
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes







Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
Also visit Ogoun the Usenet Archive
666