用wget/curl下载网址附件
专栏:web开发笔记 Aug. 3, 2025, 11:29 p.m. 42 阅读
当网址里不带文件名时怎么用命令行下载文件?

有时候我们要下载网站的网址并不是一个文件名,而是由网站服务器后台动态生成的,这时要怎样用命令行来下载呢?

可以通过检查HTTP头来获取文件名,或者使用wget的--content-disposition选项。如果服务器提供了Content-Disposition头,该选项会让wget使用服务器提供的文件名。

curl也有类似的功能,使用-J选项来根据Content-Disposition头保存文件。

方法一(使用wget):

wget --content-disposition "https://nandigits.co/download.php?id=if0&filetype=gof114_centos7"

方法二(使用curl):

curl -OJ "https://nandigits.co/download.php?id=if0&filetype=gof114_centos7"

 

感谢阅读,更多文章点击这里:【专栏:web开发笔记】
最新20篇 开设专栏