【发布时间】:2018-10-08 07:56:01
【问题描述】:
这是网址:https://www.grammarly.com
我正在尝试使用本机 get_headers() 函数获取 HTTP 标头:
$headers = get_headers('https://www.grammarly.com')
结果是
HTTP/1.1 400 Bad Request
Date: Fri, 27 Apr 2018 12:32:34 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 52
Connection: close
但是,如果我用curl 命令行工具做同样的事情,结果会有所不同:
curl -sI https://www.grammarly.com/
HTTP/1.1 200 OK
Date: Fri, 27 Apr 2018 12:54:47 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 25130
Connection: keep-alive
造成这种反应差异的原因是什么?它是在 Grammarly 的服务器端或其他方面实施不佳的安全功能吗?
【问题讨论】:
-
看起来像“安全功能实施不佳”,因为在
get_headers中设置用户代理会导致HTTP/1.1 302 Found。尝试获取您的 curl 请求标头 - 有可能设置了一些默认用户代理,您得到的是最终响应(在所有重定向之后)。 -
它可能返回 400 响应,因为在
get_headers()请求上发送了用户代理标头。
标签: php curl get-headers