从 Github Issues 下载文件

问题描述 投票:0回答:1

我正在尝试下载 Github 问题中提到的文件。

当我直接在浏览器中执行此操作时(通过其 URL) 它有效,但是当我尝试用

curl
做到这一点时, 我收到
Not found
错误。

curl https://github.com/myorg/myrep/files/15202661/00061628.pdf --header 'Authorization: token ...'

Github API 交互效果很好:

curl https://api.github.com/user --header 'Authorization: token ...

可能是什么原因?

github curl token
1个回答
0
投票

这与 HTTP 请求标头无关。在 GitHub 上,真正的文件链接并不是我们在浏览器中看到的文件链接。

https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.pdf 为例,

curl
这个链接会返回状态码 302 并且什么也不输出,只需添加
 -L
按照重定向即可成功下载。

curl -L https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld.pdf
© www.soinside.com 2019 - 2024. All rights reserved.