2010-06-14 91 views
7

如何輕鬆測試HTTP返回碼,比如說301重定向?如何測試HTTP 301重定向?

例如,如果我想 「看看這是怎麼回事」,我可以用的telnet做這樣的事情:

... $ 遠程登錄nytimes.com 80

Trying 199.239.136.200... 
Connected to nytimes.com. 
Escape character is '^]'. 

GET/HTTP/1.0

(輸入)

(輸入)

HTTP/1.1 200 OK 
Server: Sun-ONE-Web-Server/6.1 
Date: Mon, 14 Jun 2010 12:18:04 GMT 
Content-type: text/html 
Set-cookie: RMID=007af83f42dd4c161dfcce7d; expires=Tuesday, 14-Jun-2011 12:18:04 GMT; path=/; domain=.nytimes.com 
Set-cookie: adxcs=-; path=/; domain=.nytimes.com 
Set-cookie: adxcs=-; path=/; domain=.nytimes.com 
Set-cookie: adxcs=-; path=/; domain=.nytimes.com 
Expires: Thu, 01 Dec 1994 16:00:00 GMT 
Cache-control: no-cache 
Pragma: no-cache 
Connection: close 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>  
<head>  
... 

這是一個簡單的方法來訪問頗有些相關信息。

但現在我想測試301重定向確實是301重定向。

我該怎麼做?

基本上,而不是得到一個HTTP/1.1 200好我想知道我怎麼能得到301?

我知道我可以在瀏覽器中輸入網址的名稱,並「看到」我被重定向了,但我想知道什麼工具可以用來真正「看到」 301重定向。

順便說一句,我做了一個telnet測試,但是當我輸入www.example.org,我重定向到example.org(沒有www),我只能看到一個「200 OK」,我不喜歡看不到301.

回答

2

確定兩分鐘回答我找到了答案的問題...

執行以下操作不起作用:

telnet www.example.org 80 
GET/HTTP/1.0 
{enter} 
{enter} 

但以下工作正常:

telnet example.org 80 
GET/HTTP/1.0 
Host: www.example.org 
{enter} 
{enter} 

我的錯誤是通過www.example.orgtelnet(而不是example.org),然後不指定任何「主機:」

現在它的工作原理,我得到這個:

Connected to xxx.xx 
Escape character is '^]'. 
GET/HTTP/1.0 
Host: www.example.org 

HTTP/1.1 301 Moved Permanently 
Server: Apache-Coyote/1.1 
Location: http://example.org/ 
Connection: close 
Date: Mon, 14 Jun 2010 13:02:22 GMT 
Connection: close 

Connection closed by foreign host. 

注:在Windows Vista/7,Telnet客戶端是不是默認安裝的。要安裝它,按照指示在這裏:Install Telnet Client - Microsoft TechNet

+0

這不適用於Windows 7 – Krunal 2012-09-07 05:46:48

1

Firefox插件HTTP Live headers對此非常有用。後

+0

啊有趣,感謝您的鏈接...但我一直在尋找更多的東西 「低層次」,如* telnet * :)有趣的是,我找到了一個方法來發布問題後兩分鐘讓我的301 :) – NoozNooz42 2010-06-14 13:06:26

1

在頭(遠程登錄響應),你會看到它的第一行:

HTTP/1.1 301 Moved Permanently 
Via: XXXXXXXXXXX 
Connection: close 
Proxy-Connection: close 
Content-Length: 0 
Date: Mon, 14 Jun 2010 13:03:14 GMT 
Location: /xxxxxxxxx 
Server: XXXXXXX 
Cache-Control: private 

感謝

+0

其實你不以我在問題中顯示的方式,這是整點我的questi在:)看看我的答案,看看爲什麼它不是在我嘗試使用telnet的方式工作,以及需要做些什麼才能使其工作:) – NoozNooz42 2010-06-14 13:09:17

+0

您沒有在第一行301,因爲它wasn一個。如果「www」版本不是「非www」版本,它不是telnet問題,也不是我的答案。這是因爲兩個網址中的一個會這樣做,而另一個則不會。這些是2個不同的URL。 – 2010-06-14 13:37:29

15

一個在我看來,更爲方便的解決方法是使用捲曲。

只需運行:

$ curl -I http://example.com 

,它將返回的HTTP標頭這樣

HTTP/1.1 302 Moved Temporarily 
Server: nginx/1.1.19 
Date: Sun, 21 Jul 2013 10:41:47 GMT 
Content-Type: text/html 
Content-Length: 161 
Connection: keep-alive 
Location: https://other.example.com/ 
1

一個測試它是指定一個301重定向目標網站上,並使用curl -L選項方式告訴你301重定向。

-L, --location 

(HTTP) If the server reports that the requested page has moved to a different 
location (indicated with a Location: header and a 3XX response code), this option 
will make curl redo the request on the new place. 

例如:

:~$ curl -IL mail.com 

你得到:

HTTP/1.1 301 Moved Permanently 
Date: Tue, 07 Feb 2017 13:17:12 GMT 
Server: Apache 
Location: https://www.mail.com/ 
Vary: Accept-Encoding 
Connection: close 
Content-Type: text/html; charset=iso-8859-1 

HTTP/1.1 302 Found 
Date: Tue, 07 Feb 2017 13:17:13 GMT 
Server: Apache 
Vary: X-Forwarded-Proto,Host 
Set-Cookie: cookieKID=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Thu, 09-Mar-2017 13:17:13 GMT; Path=/ 
Set-Cookie: cookiePartner=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Thu, 09-Mar-2017 13:17:13 GMT; Path=/ 
Cache-Control: no-cache, no-store, must-revalidate 
Pragma: no-cache 
Expires: Thu, 01 Jan 1970 00:00:00 GMT 
Location: https://www.mail.com/int/ 
Content-Language: en-US 
Connection: close 

HTTP/1.1 200 OK 
Date: Tue, 07 Feb 2017 13:17:13 GMT 
Server: Apache 
Vary: X-Forwarded-Proto,Host,Accept-Encoding 
Set-Cookie: cookieKID=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Thu, 09-Mar-2017 13:17:13 GMT; Path=/ 
Set-Cookie: cookiePartner=kid%40autoref%40mail.com; Domain=.mail.com; Expires=Thu, 09-Mar-2017 13:17:13 GMT; Path=/ 
Cache-Control: no-cache, no-store, must-revalidate 
Pragma: no-cache 
Expires: Thu, 01 Jan 1970 00:00:00 GMT 
Set-Cookie: JSESSIONID=964DA3BD186E264928A8C188E3BB919D; Path=/mailcom-webapp/; HttpOnly 
Content-Language: en-INT 
Content-Length: 74356 
Connection: close 
Content-Type: text/html;charset=UTF-8