如何使用Linux命令行检查网站标头

检查网站标头最简单的工具是curl

在下面的示例中,我们将检查google.com的HTTP标头:

$ curl -I google.com
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.com.au/?gfe_rd=cr&ei=9Mb0VKXbHNLu8weZ24Bo
Content-Length: 260
Date: Mon, 02 Mar 2014 20:24:20 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.08

如果我们希望下载网站内容并包含标头,那么使用:

$ curl -i google.com

检查网站标头的另一个选项是使用'lynx'命令:

$ lynx -head -dump http://google.com
HTTP/1.0 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.com.au/?gfe_rd=cr&ei=rcj0VMLXJcXu8wfvoIGwBw
Content-Length: 262
Date: Mon, 02 Mar 2014 20:31:41 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.08

当然,“wget”还可以使用“--server response”选项提取网站的HTTP标头。例如:

$ wget -q --server-response http://google.com
  HTTP/1.1 302 Found
  Cache-Control: private
  Content-Type: text/html; charset=UTF-8
  Location: http://www.google.com.au/?gfe_rd=cr&ei=Isr0VJCHNsvu8weFwoG4Bw
  Content-Length: 262
  Date: Mon, 02 Mar 2014 20:37:54 GMT
  Server: GFE/2.0
  Alternate-Protocol: 80:quic,p=0.08
  HTTP/1.1 200 OK
  Date: Mon, 02 Mar 2014 20:37:55 GMT
  Expires: -1
  Cache-Control: private, max-age=0
  Content-Type: text/html; charset=ISO-8859-1
  Set-Cookie: PREF=ID=97c97a203aeb6610:FF=0:TM=1425328675:LM=1425328675:S=eXgtzGUbv53_2_TC; expires=Wed, 01-Mar-2015 20:37:55 GMT; path=/; domain=.google.com.au
  Set-Cookie: NID=67=hW7zo2M6vOcFnwq4vvUloeE8NxM5n6L_jbJocYSA0yirrh4QTviVmvqcLOW2WM4KjJGLi01xIa9O0PrhWaPqKBtP_hz1wINF2nW7trMfR0T2aXyEDoNuDNeUUXAAjIhB; expires=Tue, 01-Sep-2014 20:37:55 GMT; path=/; domain=.google.com.au; HttpOnly
  P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
  Server: gws
  X-XSS-Protection: 1; mode=block
  X-Frame-Options: SAMEORoirN
  Alternate-Protocol: 80:quic,p=0.08
  Accept-Ranges: none
  Vary: Accept-Encoding
  Transfer-Encoding: chunked
日期:2020-07-07 20:54:56 来源:oir作者:oir