0
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

header('content-type: text/plain');

$host='www.google.com';

$fp = fsockopen($host, 80);

$out = "GET http://www.google.com/ HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);

while (!feof($fp)) {
    echo fgets($fp, 128);
}

?>

这行得通。

是否符合标准?

4

2 回答 2

2

是的。

规范

Request-Line = Method SP Request-URI SP HTTP-Version CRLF

...和...

Request-URI = "*" | absoluteURI | abs_path | authority
于 2013-05-11T20:18:15.570 回答
1

是的,根据RFC 2616 的 5.1.2

一个示例请求行将是:

  GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

为了允许absoluteURIs在 HTTP 的未来版本中转换到所有请求,所有 HTTP/1.1 服务器必须接受absoluteURI请求中的表单,即使 HTTP/1.1 客户端只会在对代理的请求中生成它们。

于 2013-05-11T20:18:26.363 回答