您的位置:首页 > 编程语言 > PHP开发

php+socket模拟get,post请求

2013-12-31 08:55 429 查看
它可以伪造c
<?php

class Http {
public $requestUrlInfo=array();
public $requestLine;//请求行
public $requestHeader=array();//请求头信息
public $requestBody;//请求主体信息
public $fh=null;
/**
* 分析 url 并且连接上url
*/
public function __construct($url){
$this->requestUrlInfo=parse_url($url);
if(!isset($this->requestUrlInfo['port'])){
$this->requestUrlInfo['port']=80;
}
if(!isset($this->requestUrlInfo['path'])){
$this->requestUrlInfo['path']='/';
}
$this->fh=fsockopen($this->requestUrlInfo['host'],$this->requestUrlInfo['port']);
}
/**
* 构造 请求行和请求头,主体信息
* @param unknown_type $method
* @param unknown_type $url
*/
public function writeReqeustLineAndHeaderAndBody($method="GET",$postParameters=array()){
set_time_limit(0);
$this->requestLine=$method.' '.$this->requestUrlInfo['path'].'?'.$this->requestUrlInfo['query'].' HTTP/1.1';
$this->requestHeader[]='Host:'.$this->requestUrlInfo['host'];
if($method=='POST'){
$this->requestHeader[]='Content-Type:application/x-www-form-urlencoded';
$this->requestBody=http_build_query($postParameters);
$this->requestHeader[]='Content-Length:'.strlen($this->requestBody);
}
$arr=array_merge(array($this->requestLine),$this->requestHeader,array(''),array($this->requestBody),array(''));
$str=implode("\r\n",$arr);
fwrite($this->fh, $str);
$response='';
while (!feof($this->fh)){
$response.=fread($this->fh,1024);

}
fclose($this->fh);
return $response;
}
public function setHeader($str){
$this->requestHeader[]=$str;
}
}
?>


ookie,refefer头信息,可以用于批量发贴。数据采集。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: