如何使用带有 cURL 的响应头文件名保存文件? [英] How do I save a file using the response header filename with cURL?

查看:19
本文介绍了如何使用带有 cURL 的响应头文件名保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与cURL的命令行版本有关.

This question relates to the command line version of cURL.

我正在尝试从 CGI 脚本下载文件.

I'm trying to download a file from a CGI script.

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

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

Using a browser the filename comes up as remotefilename.gz. cURL wants to save the file as dl.pl?ID=2.

如何让 cURL 使用响应标头中的文件名保存到文件中?

How do I get cURL to save to a file with the filename from the response header?

推荐答案

-J/--remote-header-name 是您想要的选项.

您将 -J 与 -O 结合使用,这使得 curl 使用URL 中的文件名部分作为其命名输出文件的主要方式,然后如果响应中有 Content-disposition: 标头,curl 将使用该名称.

You use -J in conjunction with -O, which makes curl use the file name part from the URL as its primary way to name the output file and then if there is a Content-disposition: header in the response, curl will use that name instead.

这篇关于如何使用带有 cURL 的响应头文件名保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆