PHP fsockopen 아 날로 그 전송 post set 요청
1697 단어 PHPhttp 프로 토 콜
class Http {
public $lineAndHeader;
public $path;
public $method;
public $port = 80;
public $version = 'HTTP/1.1';
public function __construct($url)
{
$this->path=parse_url($url);
$this->setLine();
}
//
public function setLine()
{
if(!isset($this->path['query'])){
$this->path['query'] = null;
}
return array($this->method.' '.$this->path['path'].'?'.$this->path['query'].' '.$this->version);
}
//
public function setHeader($header = array())
{
if(isset($this->path['port'])){
$this->port = $this->path['port'];
}
$commonHeader = array('Host: '.$this->path['host'].':'.$this->port);
return array_merge($commonHeader,$header);
}
//GET
public function get()
{
$this->method = 'GET';
$this->lineAndHeader = array_merge($this->setLine(),$this->setHeader(),array(''),array(''));
}
//POST
public function post($data)
{
$this->method='POST';
$this->lineAndHeader = array_merge($this->setLine(),$this->setHeader(array('Content-type: application/x-www-form-urlencoded','Content-length: '.strlen($data))),array(''),array($data));
}
//
public function request()
{
$str = implode("\r
",$this->lineAndHeader);
//echo $str;exit;
$fp = fsockopen($this->path['host'],$this->port,$errno,$errstr,60);
fwrite($fp, $str,strlen($str));
$res = '';
while(!feof($fp)){
$res .= fgets($fp, 512);
}
fclose($fp);
return $res;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
laravel에 yo에서 angularJs&coffeescript를 사용할 수 있도록 한다.먼저 yo 명령을 사용할 수 있어야하므로 아래에서 설치 global에 설치한 곳에서 laravel의 프로젝트 루트로 이동. 클라이언트 코드를 관리하는 디렉토리를 만들고 이동합니다. 클라이언트 환경 만들기 이것으로 히...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.