Im使用此代码
$sock = fsockopen("ssl://google.com", 443, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)'n");
fputs($sock, "GET / HTTP/1.0'r'n");
fputs($sock, "Host: google.com'r'n");
fputs($sock, "'r'n");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str'n";
$body = "";
while (!feof($sock))
$body.= fgets($sock, 4096);
fclose($sock);
echo '<div>'.$headers.'</div>';
echo '<div>'.$body.'<div>';
我收到的页面是这样的:
HTTP/1.0 301永久移动位置:https://www.google.com/内容类型:text/html;charset=UTF-8日期:2013年12月12日星期四11:03:07GMT过期时间:2014年1月11日星期六11:03:07 GMT缓存控制:public,最大年龄=2592000服务器:gws内容长度:220 X-XSS-Protection:1;mode=块X-Frame-Options:SAMEORIGIN备用协议:443:quic301移动
文件已移到此处。
我哪里错了?为什么我需要使用ssl?我可以写https吗?如果我写https,那么我会收到错误。
您正试图通过根域"google.com"访问该网站。服务器正试图将您重定向到实际包含该网站的子域:"www.google.com。添加"。"子域前缀,您将不再获得301重定向。