【问题标题】:get_headers() not displaying Content-Encoding in PHPget_headers() 在 PHP 中不显示内容编码
【发布时间】:2016-04-29 10:41:19
【问题描述】:

我正在使用函数get_headers($url,1)获取网站http://www.sportsmalayalam.com/的标题,输出如下。它没有“Content-Encoding”,但是当我通过 Google Chrome 检查同一网站的标题时,它显示的内容编码为 gzip。

运行时:print_r(get_headers($url,1));

Array ( 
[0] => HTTP/1.1 200 OK 
[1] => Date: Fri, 29 Apr 2016 10:35:20 GMT 
[2] => Content-Type: text/html; charset=UTF-8 
[3] => Connection: close 
[4] => Set-Cookie: __cfduid=d564038ff91bf8887430482dc8a8cf74b1461926119; expires=Sat, 29-Apr-17 10:35:19 GMT; path=/; domain=.sportsmalayalam.com; HttpOnly 
[5] => X-Powered-By: PHP/5.5.9-1ubuntu4.16 
[6] => Set-Cookie: PHPSESSID=empthbjqo968ak1a3cbaa6jr67; path=/ 
[7] => Expires: Thu, 19 Nov 1981 08:52:00 GMT 
[8] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
[9] => Pragma: no-cache 
[10] => Link: ; rel="https://api.w.org/" 
[11] => Link: ; rel=shortlink 
[12] => Vary: Accept-Encoding, Cookie 
[13] => Server: cloudflare-nginx 
[14] => CF-RAY: 29b21b47261e2fab-MAA 
)

来自谷歌浏览器:

【问题讨论】:

    标签: php apache nginx http-headers


    【解决方案1】:

    比较 Request 标头。 Chrome 可能正在发送一个 Accept-Encoding 标头,说明 gzip 压缩的响应是可以的,而 PHP 不是。因此,服务器的响应不同。

    【讨论】:

    • 所以我必须发送请求说我可以处理 gzip?
    • 是的。默认为“不压缩”,客户端需要显式请求它。
    • 如何发送?
    • cURL 通常是您在发出 HTTP 请求时想要做的比绝对基础更多的事情时的最佳选择。
    • 这是获取网站服务器响应时间的最佳方式吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2023-03-09
    相关资源
    最近更新 更多