Is to possible to find filename from http headers(是否可以从 http 标头中找到文件名)
问题描述
通常在下载文件时,假设使用 QNetworkAccessManager,文件名不会出现在链接的末尾.在这种情况下如何获得正确的文件名.即使链接不包含名称提示,firefox 也会始终使用正确的名称和扩展名下载文件.我们可以使用 mime 类型获得扩展的提示,但文件名呢?
Usually when downloading files, suppose using QNetworkAccessManager, the filename is not present at the end of link. How to get proper file names in that case. Even if link doesn't contain a hint of name, firefox always downloads the file with its proper name and extension. We can get a hint of extention using mime-types but what about file names.
推荐答案
是的.这是 Content-Disposition: 附件;filename=<文件名.ext> 标头.强烈建议将内容类型设置为 application/octet-stream,这样浏览器及其插件就不会试图打开它.
Yes. It's the Content-Disposition: attachment; filename=<file name.ext> header. There's a strong suggestion to set the content type to application/octet-stream so browsers and their plugins are not tempted to open it instead.
这篇关于是否可以从 http 标头中找到文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以从 http 标头中找到文件名
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
