HTTP协议积累
class CouchSimple { function CouchSimple($options) { foreach($options AS $key => $value) { $this->$key = $value; } } function send($method, $url, $post_data = NULL) { $s = fsockopen($this->host, $this->port, $errno, $errstr); if(!$s) { echo "$errno: $errstr\n"; return false; } $request = "$method $url HTTP/1.0\r\nHost: $this->host\r\n"; if ($this->user) { $request .= "Authorization: Basic ".base64_encode("$this->user:$this->pass")."\r\n"; } if($post_data) { $request .= "Content-Length: ".strlen($post_data)."\r\n\r\n"; $request .= "$post_data\r\n"; } else { $request .= "\r\n"; } fwrite($s, $request); $response = ""; while(!feof($s)) { $response .= fgets($s); } list($this->headers, $this->body) = explode("\r\n\r\n", $response); return $this->body; } }
请求头
HTTP请求的格式如下所示:
<request-line>
<headers>
<blank line>
[<request-body>]
请求方式:
GET
GET /reg.php HTTP/1.0 \r\n
Host:www.baidu.com\r\n
Authorization: Basic
POST
PUT
HEADER
DELETE
TRACE
CONNECT
OPTIONS
响应头