我可以通过 url 下载文件,但是当我从 bash 尝试时,我得到的是 html 页面而不是文件。
如何使用url重定向(301永久移动)使用curl、wget或其他东西下载文件?
UPD
来自 url 请求的标头。
HTTP/1.1 301 Moved Permanently
Date: Sat, 07 Dec 2013 10:15:28 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3
Location: http://www.somesite.com/files/html/archive.html
Vary: Accept-Encoding
Content-Type: text/html
X-Pad: avoid browser bug
使用
-L, --location
跟随重定向:
$ curl -L http://httpbin.org/redirect/1
如果重定向的 URL 指向二进制文件,那么“curl -L”将输出如下所示的内容
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
使用 -o 或 --output 下载文件。
curl -L https://aka.ms/downloadazcopy-v10-linux -o /tmp/file.tar.gz