`

PHP file_get_contents 获取请求返回头信息

 
阅读更多
PHP file_get_contents 获取请求返回头信息


Code:

  file_get_contents("http://example.com");
  var_dump($http_response_header);


Output:

array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Sat, 12 Apr 2008 17:30:38 GMT"
  [2]=>
  string(29) "Server: Apache/2.2.3 (CentOS)"
  [3]=>
  string(44) "Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT"
  [4]=>
  string(27) "ETag: "280100-1b6-80bfd280""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 438"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(38) "Content-Type: text/html; charset=UTF-8"
}


http://stackoverflow.com/questions/2107759/php-file-get-contents-and-headers
0
5
分享到:
评论

相关推荐

    解决file_get_contents无法请求https连接的方法

    错误: Warning: fopen() [function.fopen]: Unable to find the wrapper “https” – did you forget to enable it ...3.如果服务器你不能修改配置的话,那么就使用curl函数来替代file_get_contents函数,

    PHP使用file_get_contents发送http请求功能简单示例

    主要介绍了PHP使用file_get_contents发送http请求功能,结合实例形式分析了file_get_contents结合stream_context_create实现的发送post请求数据相关原理与操作技巧,需要的朋友可以参考下

    PHP curl 或 file_get_contents 获取需要授权页面的方法

    今天因工作需要,需要用 curl / file_get_contents 获取需要授权(Authorization)的页面内容,解决后写了这篇文章分享给大家。 PHP curl 扩展,能够在服务器端发起POST/GET请求,访问页面,并能获取页面的返回数据。 ...

    php中file_get_contents与curl性能比较分析

    本文实例讲述了php中file_get_contents与curl性能比较分析。...1.fopen /file_get_contents 每次请求都会重新做DNS查询,并不对 DNS信息进行缓存。但是CURL会自动对DNS信息进行缓存。对同一域名下的网页或

    php下载文件file_get_contents php input

    php下载文件file_get_contents php input php input是获得raw原始数据流,可以访问请求的原始数据的只读流 所以比$_POST更低层,能作的事情也更多

    php中file_get_content 和curl以及fopen 效率分析

    1. fopen /file_get_contents 每次请求都会重新做DNS查询,并不对DNS信息进行缓存。但是CURL会自动对DNS信息进行缓存。对同一域名下的网页或者图片的请求只需要一次DNS查询。这大大减少了DNS查询的次数。所以CURL的...

    解析file_get_contents模仿浏览器头(user_agent)获取数据

    什么是user agentUser Agent中文名为...这很有可能是服务器上做了设置,根据 User_agent判断是否为正常的浏览器请求,因为默认PHP的file_get_contents函数是不发送ua的。如果要采集这样的网站,我们就必须要让PHP模拟

    PHP中使用file_get_contents抓取网页中文乱码问题解决方法

    根据网上有朋友介绍说原因可能是服务器开了GZIP压缩,下面是用firebug查看我的网站的头信息,Gzip是开了的,请求头信息原始头信息,代码如下: 复制代码 代码如下:Accept text/html,application/xhtml+xml,ap

    file-get-contents.js:Node.js版本的file_get_contents PHP函数

    const fileGetContents = require ( 'file-get-contents' ) ; // A File request try { let data = await fileGetContents ( '/tmp/foo/bar' ) ; console . log ( data ) ; } catch ( err ) { console . log ( '...

    php file_get_contents抓取Gzip网页乱码的三种解决方法

    把抓取到的内容转下编码即可($content=iconv(“GBK”, “UTF-8//IGNORE”, $...复制代码 代码如下:请求头信息原始头信息Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding gz

    php发送get、post请求的6种方法简明总结

    方法1: 用file_get_contents 以get方式获取内容: <?php $url='https://www.jb51.net/'; $html = file_get_contents($url); echo $html; ?> 方法2: 用fopen打开url, 以get方式获取内容: <?php $...

    PHP stream_context_create()函数的使用示例

    等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。 比如说,上篇php教程中gd库实现下载网页所有图片中,第10行: 利用了stream_context_create()设置代理服务器: 复制代码 代码如下: //设置代理...

    微信小程序获取用户openId的实现方法

    微信小程序获取用户openId的实现方法 前端: wx.login({ success: function (res) { res.code }) 获取到code后,传到后台, 然后请求微信接口 ...把参数替换为自己的参数,这个接口就直接返回openId了 ...

    PHP抓取HTTPS内容和错误处理的方法

    因为所有的Hacker News API都是通过加密的HTTPS协议访问的,跟普通的HTTP协议不同,当使用PHP里的函数 file_get_contents() 来获取API里提供的数据时,出现错误 使用的代码是这样的: <?php $data = ...

    php发送http请求的常用方法分析

    1. file_get_contents();详情见:https://www.jb51.net/article/41833.htm 2. curl发送请求。 3. fsocket发送。 下面说使用curl发送。 首先环境需要配置好curl组件。 在windows中让php支持curl比较简单: 在...

    PHP请求远程地址设置超时时间的解决方法

    php请求远程地址设置超时时间,主要讲解file_get_contents、fopen、curl这三个简单常用函数设置超时时间的方法,一般情况下建议使用curl,性能最好,效率也最高。 1、file_get_contents 请求超时设置 $timeout = ...

    curl 不支持https解决方法

    curl 不支持https 请求 windows系统file_get_contents返回false远程phpstudy

Global site tag (gtag.js) - Google Analytics