file_get_contents访问http取回响应头
php 的 file_get_contents 可以直接用 url 读取网页,用来抓内容很方便。
而且用 context 参数指定请求头。
不过php手册中,对 file_get_contents 没说怎么取得响应头。
实际上,php 文件函数能访问 http 都是用的 stream wrapper 的东西,把不同形式的流包装成文件。
在用 file_get_contents 访问 http 时,stream wrapper 会把响应头放到当前作用域下的 $http_response_header 数组变量里。
例子:
file_get_contents('http://www.jbxue.com/');
var_dump($http_response_header);
您可能感兴趣的文章:
file_get_contents访问http取回响应头
PHP fopen/file_get_contents与curl性能比较
PHP CURL或file_get_contents获取网页标题的代码
php表单提交后再后退 内容则默认清空的解决方法
PHP接口--curl请求导致接收到报文不完整解决办法
JSP 服务器响应
Servlet 服务器 HTTP 响应
PHP file_get_contents超时的设置方法
php 中file_get_contents超时问题的解决方法
php判断远程url是否有效的方法