什么内容类型强制文本响应的下载? [英] What content type to force download of text response?

查看:75
本文介绍了什么内容类型强制文本响应的下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个文件流保存在最终用户的机器上的响应。该文件是纯文本,所以什么样的内容类型,我可以使用prevent显示在浏览器中的文字?

I need to stream a file to the Response for saving on the end user's machine. The file is plain text, so what content type can I use to prevent the text being displayed in the browser?

推荐答案

为了安全起见,确保在所有浏览器一致的行为,它通常是更好地使用这两种:

To be on the safe side and ensure consistent behavior in all browsers, it's usually better to use both:

Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"My Text File.txt\"

这篇关于什么内容类型强制文本响应的下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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