我正在尝试从 cloudfront 下载文件。这是来自 scala-sbt 网站的文件存档。使用浏览器 (Chrome) 时一切正常。基本上流程如下:
https://dl.bintray.com/sbt/native-packages/sbt/0.13.8/sbt-0.13.8.zip -> HTTP 302
https://d29vzk4ow07wi7.cloudfront.net/155d6ff3bc178745ad4f951b7..... -> HTTP 200
Cloudfront 网址如下所示
https://d29vzk4ow07wi7.cloudfront.net/5ed3d97f83782ac965c5eb7256fc52df41dfa317
并包含参数
response-content-disposition:attachment;filename="sbt-0.13.8.zip"
Policy:eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvNWVkM2Q5N2Y4Mzc4MmFjOTY1YzVlYjcyNTZmYzUyZGY0MWRmYTMxNz9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMnNidC0wLjEzLjguemlwJTIyIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNDM3NzI5Nzc3fSwiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjAuMC4wLjAvMCJ9fX1dfQ__
Signature:peffptUvUMLisjf3AH~QsRv~BOG3I6UMlU-MMfQRZ62D7StDWZ8cwDyraR54iq6t1avVxR3hR~p~8dDKb~bF1oSI6BlcRP0fXQZYz5DIECZ5rELA2W8XX6EIlPUmB6XHFZFlifYIalu8HG7N5WbS6Vrm87-O809GQni~AxuHw92kXrpZy~QmAShlldFNaikNtXqytA1a2ayX-yotY4tafGTvq7zhXgs2zqj4Qw0zp8Lt7rpam3DASgeBXge8mrb118qfoXMd431iMxi-4AjxncLiaDbYXbaCs7j~7SzlNd0jCyLbHbekp58nqjP9hEGdv2KixSwPw4M7D7DwlVc8pA__
Key-Pair-Id:APKAIFKFWOMXM2UMTSFA
当我使用 wget 时:
wget https://dl.bintray.com/sbt/native-packages/sbt/0.13.8/sbt-0.13.8.zip
这个 cloudfront URL 先是返回 302,然后返回 403
--2015-07-17 11:03:45-- https://dl.bintray.com/sbt/native-packages/sbt/0.13.8/sbt-0.13.8.zip
...........................................
HTTP request sent, awaiting response... 302
Location: https://d29vzk4ow07wi7.cloudfront.net/155d6ff3bc178....[following]
..........................
--2015-07-17 11:03:46- https://d29vzk4ow07wi7.cloudfront.net/155d6ff3bc178...
....................................................
HTTP request sent, awaiting response... 403 Forbidden
2015-07-17 11:03:46 ERROR 403: Forbidden.
当我使用这样的直接 cloudfront URL 时:
wget "https://d29vzk4ow07wi7.cloudfront.net/5ed3d97f8378...."
我得到了 403,然后是 200 OK(有一个循环,wget 可能缩短了这个名称)。我还使用了 -O,然后在第二次尝试中也得到了 403,然后是 200 OK。
The name is too long, 886 chars total.
.....................................
New name is 5ed3d97f8378....
--2015-07-24 09:19:30-- https://d29vzk4ow07wi7.cloudfront.net/5ed3d97f83782....
.....................................................
HTTP request sent, awaiting response... 403 Forbidden
.....................................................
Trying to shorten...
New name is 5ed3d97f8378....
--2015-07-24 09:19:30-- https://d29vzk4ow07wi7.cloudfront.net/5ed3d97f8378....
.........................................
HTTP request sent, awaiting response... 200 OK
..............................................
2015-07-24 09:19:31 (1.18 MB/s) - '5ed3d97f8378....' saved [1060604/1060604]
我是不是漏掉了什么?我没有提到任何有关 cookie 或标头的信息,因为在第二种情况下,我没有用到它们。也许第二个例子中的连接重用是关键?
Linux 版本:
Linux version 3.10.0-229.7.2.el7.x86_64 ([email protected])
(gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )
#1 SMP Tue Jun 23 22:06:11 UTC 2015
wget 版本:
GNU Wget 1.16 built on linux-gnu.