【问题标题】:Downloading a file via cURL fails , while using chrome it works通过 cURL 下载文件失败,而使用 chrome 它可以工作
【发布时间】:2023-04-05 10:34:01
【问题描述】:

即使经过大量的 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 响应中返回的 Location: http://index-of.es/ 不完整,cURL 递归地尝试连接到以“curl: (47 ) 最多 (50) 次重定向"

问题:

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

【问题讨论】:

    标签: curl


    【解决方案1】:

    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"
    

    【讨论】:

      猜你喜欢
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      相关资源
      最近更新 更多