问题描述
Wget
在301/302重定向时无法检测文件名。例如,要从
Wget
can't detect filename when 301/302 redirections. For example, to download the MySQL source code from http://www.mysql.com/downloads/mirror.php?id=408580
wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/
该文件将另存为 index.html
wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz
该文件将另存为 mysql-5.5.25a-linux2.6-x86_64.tar.gz
但第一个URL只是第二个URL的重定向,如下所示:
but the first url is only a redirection for second URL as it is shown in:
curl -I http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/
HTTP/1.1 302 Found
Date: Mon, 09 Jul 2012 06:11:50 GMT
Server: Apache/2.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: mirror=http%3A%2F%2Fcdn.mysql.com%2F; expires=Sat, 08-Jul-2017 06:11:50 GMT; path=/
Location: http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
如何 wget
保存自动(不使用 -O
参数)的.tar.gz?
How can wget
save http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/ as ".tar.gz" automatically (without using -O
argument)?
推荐答案
尝试以下命令:
wget --content-disposition http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25a-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/
当这个设置为on时,对 Content-Disposition的实验(不完全功能)支持头已启用。这可能会导致服务器对HEAD请求进行额外的往返,并且已知会遇到几个错误,这就是为什么默认情况下目前不启用。
When this is set to on, the experimental (not fully-functional) support for "Content-Disposition" header is enabled. This can result in extra round-trips to the server for a "HEAD" request and is known to suffer from a few bugs, which is why it is not currently enabled by default.
此选项对于使用 Content-Disposition 标头来描述下载文件名称的某些文件下载CGI程序很有用。
This option is useful for some file-downloading CGI programs that use "Content-Disposition" header to describe what the name of a downloaded file should be.
这篇关于当url被重定向时,如何修复wget下载文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!