«

linux curl获取头部信息,curl 命令如何获取 http header 返回的响应消息头

时间:2024-2-20 11:32     作者:韩俊     分类: Linux


curl 命令如何获取 http 请求的响应消息头信息?

主要有两种方式:

(1) 通过 --head 选项只返回消息头,等价于 -I,示例如下:

[demo@Linux ~]$ curl --head http://www.maopiaopiao.com/

curl --head www.maopiaopiao.com
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: https://www.maopiaopiao.com/

(2) 通过 -i 选项返回包含 header 内容的所有网页实体 body 信息,示例如下:

[demo@Linux ~]$ curl -i http://www.maopiaopiao.com/

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: https://www.maopiaopiao.com/

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

标签: linux

热门推荐