`curl -O` 存储一个空文件,尽管 `wget` 运行良好

use*_*935 6 command-line wget curl

我试图从https://logz.io/sample-data.

curl -O https://logz.io/sample-data
Run Code Online (Sandbox Code Playgroud)

但是,它只返回一个名为sample-data.

curl然而,与 相比,wget返回包含正确内容的文件效果很好。

wget https://logz.io/sample-data 
Run Code Online (Sandbox Code Playgroud)

我错过了curl什么?

hee*_*ayl 13

curl当 URL 端点被重定向 (301) 到另一个端点 ( https://s3.amazonaws.com/logzio-elk/apache-daily-access.log) 时,您错过了跟随重定向;使用 HEAD 方法 ( -I) 向指定 URL发送请求:

% curl -LI https://logz.io/sample-data
HTTP/1.1 301 Moved Permanently
...
...
Location: https://s3.amazonaws.com/logzio-elk/apache-daily-access.log
...

HTTP/1.1 200 OK
...
...
Server: AmazonS3
Run Code Online (Sandbox Code Playgroud)

由于curl默认情况下不遵循 HTTP 重定向,您需要curl使用-L/--location选项告诉这样做:

curl -LO https://logz.io/sample-data
Run Code Online (Sandbox Code Playgroud)

由于wget默认情况下遵循重定向,你得到与最终网址wget 为是-