/**
* patible; MSIE 6.0; Windows NT 5.1; SV1; LazyCMS.net::DownLoader)';
var $_url,$_method,$_timeout;
var $_scheme,$_host,$_port,$_path,$_query,$_referer;
var $_header;
var $_response;
/**
* 兼容PHP5模式
*
* @param 同下面的參數
*/
function __construct($url=null,$method='GET',$timeout=60){
@set_time_limit(0);
if (!empty($url)) {
$this->connect($url,$method,$timeout);
}
return $this;
}
/**
* 初始化對象
*
* @param string $url
* @param string $method
* @param int $timeout
* @return object
*/
function Httplib($url=null,$method='GET',$timeout=60){
return $this->__construct($url,$method,$timeout);
}
/**
* 改變連接url
*
* @param string $url
* @param string $method
* @param int $timeout
* @return object
*/
function connect($url=null,$method='GET',$timeout=60){
$this->_header = null;
$this->_response = null;
$this->_url = $url;
$this->_method = strtoupper(empty($method) ? 'GET' : $method);
$this->_timeout = empty($timeout) ? 30 : $timeout;
if (!empty($url)) {
$this->_parseURL($url);
}
return $this;
}
/**
* 發送請求
*
* @param array $params
* @return bool
*/
function send($params=array()) {
$header = null; $response = null; $QueryStr = null;
if (!empty($params)) { $this->_method = 'POST'; }
if (function_exists('fsockopen')) {
$fp = @fsockopen($this->_host,$this->_port,$errno,$errstr,$this->_timeout);
if (!$fp) { return false; }
$_port = ((int)$this->_port!==80) ? ':'.$this->_port : null;
$SendStr = "{$this->_method} {$this->_path}{$this->_query} HTTP/1.0\r\n";
$SendStr.= "Host:{$this->_host}{$_port}\r\n";
$SendStr.= "Accept: */*\r\n";
$SendStr.= "Referer:{$this->_referer}\r\n";
$SendStr.= "User-Agent: ".$this->_SEND_USER_AGENT."\r\n";
$SendStr.= "Pragma: no-cache\r\n";
$SendStr.= "Cache-Control: no-cache\r\n";
//如果是POST方法,分析參數
if ($this->_method=='POST') {
//判斷參數是否是數組,循環出查詢字符串
if (is_array($params)) {
$QueryStr = ');
$http->send();
$body = $http->response();
echo $body;