note 13384 deleted from ref.curl by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 20:03:28 +0000 |
| Subject: | note 13384 deleted from ref.curl by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22694@lists.php.net to get a copy of this message | ||
IF you all fail to use CURL on win32 platform, you can try this php code(this work out from my
ex-workmate):
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function : getURL
// Programmer : Alex Yau
// Date : 2001/3/13 03:50am
//
// Example : GetURL ($method,$host,$port,$path,$para_array)
// Data to pass to the cgi script
// $MyArray = array(
// "name" => 'xxx',
// "pass" => 'xxx'
// );
//
// Post Method w/parameter:
// $sth = GetURL
('POST','technology.hongkong.com',80,'/xxx.cgi',$MyArray);
//
// Get Method w/parameter:
// $sth = GetURL
('GET','technology.hongkong.com',80,'/xxx.cgi',$MyArray);
//
// Get Plain Html only
// $sth = GetURL ('GET','www.php.net',80,'','');
///////////////////////////////////////////////////////////////////////////////////////////////////////
function getURL ($this_method,$this_host,$this_port,$this_path,$this_array){
if($this_array){
// Build the request string
while ( list ($key,$val) = each ($this_array)){
$this_request .= $key.'='.urlencode($val).'&';
}
// chop the last '&' sign
if($this_request){
$this_request = substr($this_request,0,strlen($this_request)-1);
}
}else{
$this_request = '';
}
//echo $this_request;
// Build the header
if($this_method == 'POST'){
$header = "$this_method $this_path HTTP/1.0\r\n";
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-length: " . strlen($this_request) . "\r\n\r\n";
}elseif($this_method == 'GET'){
$header = "$this_method $this_path?$this_request HTTP/1.0\r\n";
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-length: " . strlen($this_request) . "\r\n\r\n";
}else{
$header = "$this_method $this_path HTTP/1.0\r\n\r\n";
}
// Open the connection
$fp = fsockopen($this_host, $this_port, &$err_num, &$err_msg, 30);
// No Connection Error
if(!$fp) {
print "Sorry, the server is not currently available!";exit;
}
// Send everything
fputs($fp, $header . $this_request);
// discard the HTTP header
while(trim(fgets($fp, 1024)) != "");
// Get the response
while (!feof($fp)) $response .= fgets($fp, 128);
return $response;
}
the $response stored the content of html file.