curl 命令如何获取 http 请求的响应消息头信息?
主要有两种方式:
(1) 通过 --head 选项只返回消息头,等价于 -I,示例如下:
[demo@Linux ~]$ curl --head http://php.hhsy.cc/
curl --head php.hhsy.cc
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 03 Nov 2021 07:18:26 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: //
(2) 通过 -i 选项返回包含 header 内容的所有网页实体 body 信息,示例如下:
[demo@Linux ~]$ curl -i http://php.hhsy.cc/
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 03 Nov 2021 07:22:15 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: //
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>