这个问题与 cURL 的命令行版本有关。
我试图从一个 CGI 脚本下载一个文件。
http://example.com/perl/dl.pl?ID=2
使用浏览器,文件名显示为 remotefilename.gz。 CURL 希望将文件保存为 dl.pl?ID=2。
remotefilename.gz
dl.pl?ID=2
如何让 cURL 保存到一个包含响应头文件名的文件中?
you can try the -o or -O option.
-o
-O
-J/--remote-header-name is the option you want.
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 http://example.com/dl.php?file=3123123 -O -J
if server uses redirection use these:
--location-trusted --max-redirs 10
curl -OJ gave me segmentation fault: 11 error when attempting to download multiple URLs at once.
curl -OJ
Instead, I used wget. The latest version supports HTTP Content-Disposition headers, which often contain filename information.
wget
wget --content-disposition http://example.com/download/url