为什么这个来自 Firefox 的 curl 命令不下载任何东西?

Tim*_*Tim 8 firefox curl

https://raw.githubusercontent.com/andreafrancia/trash-cli/master/README.rst在 Firefox 中打开,然后从 Tools->Web Developer->Network 复制以下 curl 命令:

curl 'https://raw.githubusercontent.com/andreafrancia/trash-cli/master/README.rst' -H 'Host: raw.githubusercontent.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-GB,en;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'If-None-Match: "6931c3b4d0e94743bb93a36ed8e8c3f5add12f9a"' -H 'Cache-Control: max-age=0' 
Run Code Online (Sandbox Code Playgroud)

当我在 lxterminal 中运行它时,它不会下载任何东西,即使我添加-O了它。我想知道为什么它不下载,以及如何让它下载文件?

谢谢。

Ste*_*itt 26

在调试curl问题时,该-v选项通常很有帮助。在这个特定的例子中,你正在运行If-None-Match标题,它告诉服务器你已经有匹配“6931c3b4d0e94743bb93a36ed8e8c3f5add12f9a”的文件,如果它没有改变,你没有兴趣再次检索它。-v通过指示服务器以 304 标头响应来向您展示这一点:

< HTTP/1.1 304 Not Modified
Run Code Online (Sandbox Code Playgroud)

要下载您的文件,请删除标题:

curl 'https://raw.githubusercontent.com/andreafrancia/trash-cli/master/README.rst' -H 'Host: raw.githubusercontent.com' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-GB,en;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'Cache-Control: max-age=0'
Run Code Online (Sandbox Code Playgroud)

在这个特定的例子中,你会得到相同的结果

curl 'https://raw.githubusercontent.com/andreafrancia/trash-cli/master/README.rst'
Run Code Online (Sandbox Code Playgroud)