本文共计116个文字,预计阅读时间需要1分钟。

使用file_get_contents访问https网站内容示例:
php

测试使用file_get_contents来访问 input");
$url = 'www.baidu.com';
$cookie = $_SERVER['HTTP_HHCOOKIE'] ;
echo $cookie;
echo "
";
echo $post_data;
$header = "Referer:www.baidu.com\r\n"
."User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:33.0) Gecko/20100101 Firefox/33.0\r\n"
."Cookie: ".$cookie."\r\n"
."Content-type: application/x-www-form-urlencoded;charset=UTF-8\r\n";
$options = array(
'http' => array(
'method' => "POST",
'header' => $header,
'content' => $post_data,
'timeout' => 15 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
var_dump($http_response_header) ;
}
}
$http = new HttpsUtil();
$http->testPost();
?>