我正在尝试下载 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 ...
可能是什么原因?
这与 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