如何才能知道网站重定向返回的 http 代码是什么?

如何才能知道网站重定向返回的 http 代码是什么?

有一个网站,当您访问某些链接时,它会将您重定向到另一个网站。

有什么方法可以让我找出在他们重定向您之前返回的 HTTP 代码吗?

答案1

当然,试试 curl:

$ curl -k https://www.gmail.com/
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>

答案2

curl,,wget... 其他命令行网络浏览器可能并非在所有操作系统上都可用,请改用telnet

$ telnet localhost 81
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /one/two?path=x&y=z HTTP/1.0
<enter>
<enter>
HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.5
Date: Sat, 15 Oct 2011 02:38:59 GMT
Content-Type: text/html
Content-Length: 184
Location: http://127.0.0.1:81/one/two/x?y=z
Connection: close

您还可以传递Host标题:

telnet www.ganglia.gentoo 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Host: www.ganglia.gentoo
<enter>
<enter>
HTTP/1.1 301 Moved Permanently
Date: Sat, 15 Oct 2011 02:45:41 GMT
Server: Apache
Location: http://nagios.gentoo/
Content-Length: 297
Connection: close
Content-Type: text/html; charset=iso-8859-1

相关内容