首页主机content-Disposition(ContentDisposition是什么)

content-Disposition(ContentDisposition是什么)

编程之家2024-05-0987次浏览

一、Content-disposition中Attachment和inline的区别

区别是:

content-Disposition(ContentDisposition是什么)

java web中文件时,我们一般设置 Content-Disposition告诉浏览器文件的名称,是否在浏览器中内嵌显示。

Content-disposition: inline; filename=foobar.pdf

表示浏览器内嵌显示一个文件。

Content-disposition: attachment; filename=foobar.pdf

表示会文件,如浏览器中。

词汇解释:

content-Disposition(ContentDisposition是什么)

attachment英[??t?t?m?nt]美[??t?t?m?nt]

n.(用电子发送的)附件,附属物;依恋,依附;扣押财产<法>逮捕,扣押(人,财产);

[例句]As a teenager she formed a strong attachment to one of her teachers.

少女时代的她曾迷上了自己的一个老师。

inline英['?n,la?n]美[?nla?n]

[词典] [计]内联;

content-Disposition(ContentDisposition是什么)

[例句]CREATE with errors support has been added for the views and inline SQL functions.

为视图和内联SQL函数添加了带有错误支持的CREATE。

二、js 模拟POST提交enctype="multipart/form-data"类型的表单

只是需要文件上传才用它的

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");

改成

xmlHttp.setRequestHeader("Content-Type","multipart/form-data;");

至于发送二进制数据,你自己解决吧。

-----------------------------7db8c30150364这个其实有规律的

就是一个开始段一个结束段,7db8c30150364只是用一串不重复的字符,标识一起其中间的东西就是数据,Content-Disposition: form-data; name="polls[]"这个是用来表示什么数据,文件名是啥。

其实在socket发包中,上传文件的时候就要这么用,有空研究一下HTTP里面POST文件时,应该如何处理。

三、怎么使用添加content-disposition

在进行Web开发时,可能遇到遇到以下几种需求:

l

希望某类或者某已知MIME

类型的文件(比如:*.gif;*.txt;*.htm)能够在访问时弹出逗文件下载地对话框。

l

希望客户端下载时以指定文件名显示。

l

希望某文件直接在浏览器上显示而不是弹出文件下载对话框。

对于上面的需求,使用Content-Disposition属性就可以解决。下面是代码示例:

response.setHeader("Content-disposition",

"attachment;filename="

+

fileName)。

//Content-disposition为属性名。

//attachment表示以附件方式下载。如果要在页面中打开,则改为inline。

//filename如果为中文,则会出现乱码。解决办法有两种:

//1、使用fileName

=

new

String(fileName.getBytes(),

"ISO8859-1")语句

//2、使用fileName

=

HttpUtility.UrlEncode(filename,

System.Text.Encoding.UTF8)语句

itech(itech是什么)百度云刷机(百度云刷机怎么操作)