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

查看:140
本文介绍了如何使用带有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?

推荐答案

如果您有足够的卷曲(版本7.20) .0或更高版本), -J /-远程标头名称就是您想要的。

if you have a new enough curl (version 7.20.0 or later), -J/--remote-header-name is what you want.

您将-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天全站免登陆