代码之家  ›  专栏  ›  技术社区  ›  John

如何使用带有cURL的响应头文件名保存文件

  •  39
  • John  · 技术社区  · 16 年前

    http://example.com/perl/dl.pl?ID=2
    

    使用浏览器,文件名显示为 remotefilename.gz . cURL想将文件另存为 dl.pl?ID=2 .

    如何让cURL从响应头保存到文件名为的文件?

    4 回复  |  直到 6 年前
        1
  •  119
  •   Daniel Stenberg    5 年前

    -J/--remote-header-name 是你想要的选择。

    -O ,这使得curl使用URL中的文件名部分作为命名输出文件的主要方式,然后如果响应中有Content-disposition:header,curl将使用该名称。

        2
  •  22
  •   animuson    14 年前
    curl http://example.com/dl.php?file=3123123 -O -J
    

    --location-trusted
    --max-redirs 10
    
        3
  •  19
  •   jchook    6 年前

    curl -OJ

    wget . 最新版本支持HTTP内容处置头,通常包含文件名信息。

    wget --content-disposition http://example.com/download/url
    
        4
  •  -5
  •   ghostdog74    16 年前

    你可以试试这个 -o -O

    推荐文章