2013-01-16 26 views
3

我正在構建一個閱讀網頁的程序。我試圖讀取301永久移動 - 重定向頁面的新鏈接在哪裏?

http://en.wikipedia.org/wiki/France 

但後來我得到的迴應:

HTTP/1.0 301 Moved Permanently. 

我無法理解的是,新的鏈接(在場上的位置)是我給了相同的。 ..那麼重定向頁面的新鏈接在哪裏?

這裏是迴應:

HTTP/1.0 301 Moved Permanently 
    Date: Wed, 16 Jan 2013 22:26:03 GMT 
    Server: Apache 
    X-Content-Type-Options: nosniff 
    Cache-Control: private, s-maxage=0, max-age=0, must-revalidate 
    Vary: Accept-Encoding,X-Forwarded-Proto,Cookie 
    Last-Modified: Wed, 16 Jan 2013 22:26:03 GMT 
    Location: http://en.wikipedia.org/wiki/France 
    Content-Length: 0 
    Content-Type: text/html; charset=utf-8 
    X-Cache: MISS from sq64.wikimedia.org 
    X-Cache-Lookup: HIT from sq64.wikimedia.org:3128 
    Age: 45 
    X-Cache: HIT from amssq32.esams.wikimedia.org 
    X-Cache-Lookup: HIT from amssq32.esams.wikimedia.org:3128 
    X-Cache: MISS from amssq35.esams.wikimedia.org 
    X-Cache-Lookup: MISS from amssq35.esams.wikimedia.org:80 
    Connection: close 

感謝


據埃裏克答案,我再次測試我的程序。

我給後續命令:

GET http://www.wikipedia.org/wiki/france HTTP/1.1 

的反應是:

HTTP/1.0 301 Moved Permanently 
    Date: Thu, 17 Jan 2013 22:36:04 GMT 
    Server: Apache 
    Location: http://en.wikipedia.org/wiki/france 
    Content-Length: 243 
    Content-Type: text/html; charset=iso-8859-1 
    X-Cache: MISS from sq64.wikimedia.org 
    X-Cache-Lookup: MISS from sq64.wikimedia.org:3128 
    X-Cache: MISS from amssq45.esams.wikimedia.org 
    X-Cache-Lookup: MISS from amssq45.esams.wikimedia.org:3128 
    X-Cache: MISS from knsq26.knams.wikimedia.org 
    X-Cache-Lookup: MISS from knsq26.knams.wikimedia.org:80 
    Connection: close 

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
    <html><head> 
    <title>301 Moved Permanently</title> 
    </head><body> 
    <h1>Moved Permanently</h1> 
    <p>The document has moved <a href="http://en.wikipedia.org/wiki/france">here</a>.</p> 
    </body></html> 

預計這當然。 現在我送:

GET http://en.wikipedia.org/wiki/france HTTP/1.1 

而且反應是:

HTTP/1.0 301 Moved Permanently 
    Date: Wed, 16 Jan 2013 22:26:03 GMT 
    Server: Apache 
    X-Content-Type-Options: nosniff 
    Cache-Control: private, s-maxage=0, max-age=0, must-revalidate 
    Vary: Accept-Encoding,X-Forwarded-Proto,Cookie 
    Last-Modified: Wed, 16 Jan 2013 22:26:03 GMT 
    Location: http://en.wikipedia.org/wiki/France 
    Content-Length: 0 
    Content-Type: text/html; charset=utf-8 
    X-Cache: MISS from sq64.wikimedia.org 
    X-Cache-Lookup: HIT from sq64.wikimedia.org:3128 
    Age: 45 
    X-Cache: HIT from amssq32.esams.wikimedia.org 
    X-Cache-Lookup: HIT from amssq32.esams.wikimedia.org:3128 
    X-Cache: MISS from amssq35.esams.wikimedia.org 
    X-Cache-Lookup: MISS from amssq35.esams.wikimedia.org:80 
    Connection: close 

我試着用wget的:

wget.exe http://en.wikipedia.org/wiki/france 

及其OK!該頁面已加載:

wget.exe http://en.wikipedia.org/wiki/france 
    --2013-01-18 00:43:06-- http://en.wikipedia.org/wiki/france 
    Resolving en.wikipedia.org... 91.198.174.225 
    Connecting to en.wikipedia.org|91.198.174.225|:80... connected. 
    HTTP request sent, awaiting response... 301 Moved Permanently 
    Location: http://en.wikipedia.org/wiki/France [following] 
    --2013-01-18 00:43:06-- http://en.wikipedia.org/wiki/France 
    Reusing existing connection to en.wikipedia.org:80. 
    HTTP request sent, awaiting response... 200 OK 
    Length: 854896 (835K) [text/html] 
    Saving to: `France' 

    100%[======================================>] 854,896  573K/s in 1.5s 

    2013-01-18 00:43:08 (573 KB/s) - `France' saved [854896/854896] 

那麼,我的程序有什麼不好?

+0

您能顯示請求嗎? –

+0

這是您請求的實際頁面嗎?我得到了200 OK的迴應,也許網絡中的某些內容配置錯誤。 –

回答

2

位置標題是新地址應該出現的位置。在這種情況下,它會導致Web瀏覽器不斷嘗試重新加載它,直到它放棄「太多重定向」錯誤。

如果我使用上面使用的URL,我會得到200回報。如果我使用「wget的--server響應http://wikipedia.org/wiki/France」,有趣的位是:

wget --server-response http://wikipedia.org/wiki/France 
--2013-01-16 18:10:59-- http://wikipedia.org/wiki/France 
Resolving wikipedia.org... 208.80.152.201, 2620:0:860:ed1a::1 
Connecting to wikipedia.org|208.80.152.201|:80... connected. 
HTTP request sent, awaiting response... 
    HTTP/1.0 301 Moved Permanently 
    Date: Wed, 16 Jan 2013 23:10:59 GMT 
    Server: Apache 
    Location: http://www.wikipedia.org/wiki/France 
    Content-Length: 244 
    Content-Type: text/html; charset=iso-8859-1 
    X-Pad: avoid browser bug 
    X-Cache: MISS from sq65.wikimedia.org 
    X-Cache-Lookup: MISS from sq65.wikimedia.org:3128 
    X-Cache: MISS from sq64.wikimedia.org 
    X-Cache-Lookup: MISS from sq64.wikimedia.org:80 
    Connection: keep-alive 
Location: http://www.wikipedia.org/wiki/France [following] 
--2013-01-16 18:10:59-- http://www.wikipedia.org/wiki/France 
Resolving www.wikipedia.org... 208.80.154.225, 2620:0:861:ed1a::1 
Connecting to www.wikipedia.org|208.80.154.225|:80... connected. 
HTTP request sent, awaiting response... 
    HTTP/1.0 301 Moved Permanently 
    Date: Wed, 16 Jan 2013 23:11:00 GMT 
    Server: Apache 
    Location: http://en.wikipedia.org/wiki/France 
    Content-Length: 243 
    Content-Type: text/html; charset=iso-8859-1 
    X-Cache: MISS from cp1019.eqiad.wmnet 
    X-Cache-Lookup: MISS from cp1019.eqiad.wmnet:3128 
    X-Cache: MISS from cp1018.eqiad.wmnet 
    X-Cache-Lookup: MISS from cp1018.eqiad.wmnet:80 
    Connection: keep-alive 
Location: http://en.wikipedia.org/wiki/France [following] 
--2013-01-16 18:11:00-- http://en.wikipedia.org/wiki/France 
Resolving en.wikipedia.org... 208.80.154.225, 2620:0:861:ed1a::1 
Reusing existing connection to www.wikipedia.org:80. 
HTTP request sent, awaiting response... 
    HTTP/1.0 200 OK 

正如你所看到的wget是繼從wikipedia.org重定向到www.wikipedia.org終於en.wikipedia。有機我會重新檢查您的網址,並確保您沒有使用www.wikipedia.org。如果你不是,那麼它的服務器肯定是一個暫時的錯誤。祝你好運!

+0

謝謝埃裏克,但它仍然似乎我做錯了什麼。我發現我不能在評論中寫下它。我是新來的..會找到方法。 – audi02

+0

我根據你的回答編輯了我的測試題。 – audi02

+0

希望我沒有困惑你。我添加了http://wikipedia.org/wiki/France的請求,因爲我知道這會導致重定向並給你一個正常重定向的例子。請記住,雖然主機名不區分大小寫,但其餘的URI區分大小寫。 http://en.wikipedia.org/wiki/france與http://en.wikipedia.org/wiki/France不同。確保您的程序正在使用http://en.wikipedia.org/wiki/France。使用小寫版本將導致301轉發。 –

0

問題是我的程序在內部將給定的地址改爲小寫。 這導致鏈接與小寫'f'而不是大寫'F',根據301響應需要與「法國」。

我認爲URL不區分大小寫,但現在我知道了:

「雖然域名不區分大小寫的,該URL的其餘部分可能是」(http://www.wisegeek.com /是-網址區分大小寫。htm)