只需要输出response头即可。
其中,-I
选项表示只输出HTTP头信息,而不下载整个页面内容。 <URL>
是要测试的网址。
如果该网址有301/302重定向,curl会输出HTTP头信息,以及重定向后的URL地址。例如:
curl -I <url>
#>curl -I https://www.xxx.com/index.php?p=contact
HTTP/1.1 301 Moved Permanently
Date: Wed, 26 Apr 2023 15:30:12 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Wed, 26 Apr 2023 16:30:12 GMT
Location: https://www.xxx.com/contact/
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s="}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 7bdfdd111cff7767-LHR
curl -o vue-v2.6.10.js https://cdn.jsdelivr.net/npm/vue/dist/vue.js
#vue.js 保存为vue-v2.6.10.js
curl -O https://cdn.jsdelivr.net/npm/vue/dist/vue.js
# -O 直接保存为原文件名
curl -I https://www.ubuntu.com/
# 获得HTTP HEADER
curl -I --http2 https://www.ubuntu.com
# --https2 检查是否支持http2协议
curl -L google
# -L 命令curl 跟随跳转到final destination
curl -A "googlebot" https://www.ubuntu.com
# -A 自定义UA
curl -x 192.168.66.1:8888 http://linux
# -x 或者 --proxy 设定proxy
curl -H "X-Header: value" https://www.keycdn.com
# -H 自定义header
curl -H "X-Header: value" https://www.keycdn.com -v
# -v 表示 verbose
curl -h # -h 表示manual
curl --request GET/POST https://www.keycdn.com
# curl 默认是GET, --request 可以自定为GET或者POST