通过cURL下载文件失败,而使用chrome则可以正常工作

时间:2017-07-18 14:38:23

标签: curl

即使经历了很多stackoverflow的答案,我也无法找到问题的解决方案。因此我再次问它。

我正在尝试使用以下命令下载http://index-of.es/Magazines/hakin9/books/No.Starch.TCP.IP.Guide.Oct.2005.pdf

curl  -o tcp.pdf   --cookie coockie -L  http://index-of.es/Magazines/hakin9/books/No.Starch.TCP.IP.Guide.Oct.2005.pdf
--verbose

输出:

$ curl  -o tcp.pdf   --cookie coockie -L  http://index-of.es/Magazines/hakin9/books/No.Starch.TCP.IP.Guide.Oct.2005.pdf   --verbose
* Adding handle: conn: 0xb65698
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0xb65698) send_pipe: 1, recv_pipe: 0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to index-of.es port 80 (#0)
*   Trying 87.98.231.4...
* Connected to index-of.es (87.98.231.4) port 80 (#0)
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0> GET /Magazines/hakin9/books/No.Starch.TCP.IP.Guide.Oct.2005.pdf HTTP/1.1
> User-Agent: curl/7.30.0
> Host: index-of.es
> Accept: */*
> Cookie: 240plan=R130020614; 240planBAK=R2339305415
>
< HTTP/1.1 302 Found
* Replaced cookie 240plan="R130020614" for domain index-of.es, path /, expire 1500391330
< Set-Cookie: 240plan=R130020614; path=/; expires=Tue, 18-Jul-2017 15:22:10 GMT
< Date: Tue, 18 Jul 2017 14:20:33 GMT
* Server Apache is not blacklisted
< Server: Apache
< Location: http://index-of.es/
< Vary: Accept-Encoding
< Content-Length: 203
< Content-Type: text/html; charset=iso-8859-1
< X-IPLB-Instance: 177
<
* Ignoring the response-body
{ [data not shown]
100   203  100   203    0     0    166      0  0:00:01  0:00:01 --:--:--   169
* Connection #0 to host index-of.es left intact
* Issue another request to this URL: 'http://index-of.es/'

我怀疑问题是HTTP响应中返回的位置:http://index-of.es/ ,这是不完整的,cURL递归尝试连接到以 curl结尾的相同位置: (47)最多(50)次重定向

问题:

  • chrome如何下载文件?    如果我使用的命令不完整,还需要在命令中添加什么?

1 个答案:

答案 0 :(得分:0)

似乎Curl用户代理已在该服务器上列入黑名单,更改User-Agent标题:

curl -o tcp.pdf \
     -H "User-Agent: Mozilla" \
     -L "http://index-of.es/Magazines/hakin9/books/No.Starch.TCP.IP.Guide.Oct.2005.pdf"