From cf4041ca7fb36ecf2e8bcce17d6c503e4d5aaf64 Mon Sep 17 00:00:00 2001 From: zhengsihua Date: Thu, 6 Nov 2014 20:03:25 +0800 Subject: [PATCH] Linux FAQs with Answers--How to disable HTTP redirect in wget --- ...s--How to disable HTTP redirect in wget.md | 35 ------------------- ...s--How to disable HTTP redirect in wget.md | 33 +++++++++++++++++ 2 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 sources/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md create mode 100644 translated/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md diff --git a/sources/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md b/sources/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md deleted file mode 100644 index 8b2551568f..0000000000 --- a/sources/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md +++ /dev/null @@ -1,35 +0,0 @@ -Translating-------geekpi - -Linux FAQs with Answers--How to disable HTTP redirect in wget -================================================================================ -> **Question**: When I run wget to fetch a URL X which is redirected to another URL Y, wget, by default, goes fetch URL Y automatically. However, I would like to force wget to only fetch the original URL X without following the redirection. How can I stop wget from following a redirected URL? - -In the HTTP specification, a redirect response (with 3XX HTTP response) indicates to the web browser that the requested URL is moved at another location. The redirect response then contains the URL of the redirect target. - -Like regular HTTP clients, wget supports URL redirection (also known as URL forwarding), which means that when you attempt to download a redirected URL, wget will automatically follow URL redirect to fetch the redirected target. If for some reason you want to disable URL direction, and stop with 3XX status code, you can use "--max-redirect=number" option with wget. This option is used to specify the maximum number of (recursive) redirections to follow, which is set to 20 by default. - -If you want to disable HTTP redirects in wget, use "--max-redirect=0" option as follows. - - $ wget --max-redirect=0 http://www.aaa.com/a.html - ----------- - - --2014-10-31 23:08:58-- http://www.aaa.com/a.html - Resolving aaa.com (aaa.com)... 1.2.3.4 - Connecting to aaa.com (aaa.com)|1.2.3.4|:80... connected. - HTTP request sent, awaiting response... 301 Moved Permanently - Location: http://www.bbb.com/b.html [following] - 0 redirections exceeded. - -As you can see, when wget encounters a HTTP redirect reponse, it does not follow the redirection, and simply stop with "0 redirections exceeded" error message. It will also show a received HTTP status code (e.g., 301). - -Note that curl, which is another similar HTTP client, behave oppositely. By default, curl does NOT follow URL redirection. To force curl to redirect a URL, you have to use "-L" option. - --------------------------------------------------------------------------------- - -via: http://ask.xmodulo.com/disable-http-redirect-wget.html - -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 \ No newline at end of file diff --git a/translated/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md b/translated/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md new file mode 100644 index 0000000000..c6beb3b802 --- /dev/null +++ b/translated/tech/20141105 Linux FAQs with Answers--How to disable HTTP redirect in wget.md @@ -0,0 +1,33 @@ +Linux 有问必答 -- 如何在wget中禁用HTTP转发 +================================================================================ +> **提问**: 当我用wget获取一个重定向到URL Y的URL X的时候,wget默认会自动获取URL Y。然而我想要强制获取不带重定向的URL X。我该如何禁用wget重定向URL的功能。 + +在HTTP标准中,重定向响应(带3XX的HTTP响应)说明请求的URL被移到了新的位置。重定向相应接着包含了目标重定向的URL。 + +像常规的HTTP客户端,wget支持URL重定向(也叫URL转发),意味着当你尝试下载一个重定向的URL时,wget会自动跟随URL重定向获取重定向后的资源。如果你由于一些原因想要禁用URL重定向,并停止3XX的状态码,你可以使用wget的“--max-redirect=number”选项。这个选项用来指定最大(递归)重定向的数字,默认是20。 + +如果你想要禁用wget中的HTTP重定向,使用“--max-redirect=0” + + $ wget --max-redirect=0 http://www.aaa.com/a.html + +---------- + + --2014-10-31 23:08:58-- http://www.aaa.com/a.html + Resolving aaa.com (aaa.com)... 1.2.3.4 + Connecting to aaa.com (aaa.com)|1.2.3.4|:80... connected. + HTTP request sent, awaiting response... 301 Moved Permanently + Location: http://www.bbb.com/b.html [following] + 0 redirections exceeded. + +如你所见,当wget遇到HTTP重定向响应时,它不会跟着重定向,并以“0 redirections exceeded”(超出0次重定向)的错误信息停止。它同样会显示一个HTTP的状态码(比如301)。 + +注意一下curl,另外一个类似的HTTP客户端,行为正好相反。默认上,curl并不会跟随URL重定向。要强制使cutl重定向到一个URL,你要使用“-L”选项。 + +-------------------------------------------------------------------------------- + +via: http://ask.xmodulo.com/disable-http-redirect-wget.html + +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 \ No newline at end of file