目录搜索
GuidesAccess control CORSAuthenticationBrowser detection using the user agentCachingCaching FAQCompressionConditional requestsConnection management in HTTP 1.xContent negotiationContent negotiation: List of default Accept valuesCookiesCSPMessagesOverviewProtocol upgrade mechanismProxy servers and tunnelingProxy servers and tunneling: Proxy Auto-Configuration (PAC) filePublic Key PinningRange requestsRedirectionsResources and specificationsResources and URIsResponse codesServer-Side Access ControlSessionGuides: BasicsBasics of HTTPChoosing between www and non-www URLsData URIsEvolution of HTTPIdentifying resources on the WebMIME TypesMIME types: Complete list of MIME typesCSPContent-Security-PolicyContent-Security-Policy-Report-OnlyCSP: base-uriCSP: block-all-mixed-contentCSP: child-srcCSP: connect-srcCSP: default-srcCSP: font-srcCSP: form-actionCSP: frame-ancestorsCSP: frame-srcCSP: img-srcCSP: manifest-srcCSP: media-srcCSP: object-srcCSP: plugin-typesCSP: referrerCSP: report-uriCSP: require-sri-forCSP: sandboxCSP: script-srcCSP: style-srcCSP: upgrade-insecure-requestsCSP: worker-srcHeadersAcceptAccept-CharsetAccept-EncodingAccept-LanguageAccept-RangesAccess-Control-Allow-CredentialsAccess-Control-Allow-HeadersAccess-Control-Allow-MethodsAccess-Control-Allow-OriginAccess-Control-Expose-HeadersAccess-Control-Max-AgeAccess-Control-Request-HeadersAccess-Control-Request-MethodAgeAllowAuthorizationCache-ControlConnectionContent-DispositionContent-EncodingContent-LanguageContent-LengthContent-LocationContent-RangeContent-TypeCookieCookie2DateDNTETagExpectExpiresForwardedFromHeadersHostIf-MatchIf-Modified-SinceIf-None-MatchIf-RangeIf-Unmodified-SinceKeep-AliveLarge-AllocationLast-ModifiedLocationOriginPragmaProxy-AuthenticateProxy-AuthorizationPublic-Key-PinsPublic-Key-Pins-Report-OnlyRangeRefererReferrer-PolicyRetry-AfterServerSet-CookieSet-Cookie2SourceMapStrict-Transport-SecurityTETkTrailerTransfer-EncodingUpgrade-Insecure-RequestsUser-AgentUser-Agent: FirefoxVaryViaWarningWWW-AuthenticateX-Content-Type-OptionsX-DNS-Prefetch-ControlX-Forwarded-ForX-Forwarded-HostX-Forwarded-ProtoX-Frame-OptionsX-XSS-ProtectionMethodsCONNECTDELETEGETHEADMethodsOPTIONSPATCHPOSTPUTStatus100 Continue101 Switching Protocols200 OK201 Created202 Accepted203 Non-Authoritative Information204 No Content205 Reset Content206 Partial Content300 Multiple Choices301 Moved Permanently302 Found303 See Other304 Not Modified307 Temporary Redirect308 Permanent Redirect400 Bad Request401 Unauthorized403 Forbidden404 Not Found405 Method Not Allowed406 Not Acceptable407 Proxy Authentication Required408 Request Timeout409 Conflict410 Gone411 Length Required412 Precondition Failed413 Payload Too Large414 URI Too Long415 Unsupported Media Type416 Range Not Satisfiable417 Expectation Failed426 Upgrade Required428 Precondition Required429 Too Many Requests431 Request Header Fields Too Large451 Unavailable For Legal Reasons500 Internal Server Error501 Not Implemented502 Bad Gateway503 Service Unavailable504 Gateway Timeout505 HTTP Version Not Supported511 Network Authentication RequiredStatus
文字

在常规 HTTP 响应中,Content-Disposition响应标头是指示内容是否预期在浏览器中内联显示的标题,即,作为网页或作为网页的一部分或作为附件下载并且本地保存。

在一个multipart/form-data正文中,HTTP Content-Disposition通用标题是一个标题,可以在多部分主体的子部分中使用,以提供有关它适用的字段的信息。子部分由标题中定义的边界分隔Content-Type。用于身体本身,Content-Disposition没有任何作用。

所述Content-Disposition的 header 在 MIME 消息的电子邮件的更大的范围内定义的,但仅可能的参数的子集应用于 HTTP 形式和POST请求。只有值form-data,以及可选的指令namefilename,可以在 HTTP 上下文中使用。

Header type

Response header (for the main body) General header (for a subpart of a multipart body)

Forbidden header name

no

语法

作为主体的响应标题

HTTP 上下文中的第一个参数是inline(默认值,表示它可以显示在网页内,或作为网页)或attachment(表示它应该下载;大多数浏览器呈现“另存为”对话框,预先填入filename如果存在参数的值

Content-Disposition: inline
Content-Disposition: attachment
Content-Disposition: attachment; filename="filename.jpg"

作为多部分主体的 header

HTTP 上下文中的第一个参数总是form-data; 其他参数不区分大小写,并且有参数,在'='符号后面使用带引号的字符串语法。多个参数用分号(';')分隔。

Content-Disposition: form-data
Content-Disposition: form-data; name="fieldName"Content-Disposition: form-data; name="fieldName"; filename="filename.jpg"

指令

name后面跟着一个字符串,其中包含该字段的内容引用的 HTML 字段的名称。在同一字段中处理多个文件(例如元素的multiple属性<input type=file>)时,可能会有几个具有相同名称的子部分。

一个name有值'_charset_'表明该部分不是 HTML 区域,但默认字符集,而无需显式的字符集信息使用的部分。

filename后面是一个包含传输文件的原始名称的字符串。文件名始终是可选的,不能被应用程序盲目使用:路径信息应该被删除,并且应该转换为服务器文件系统规则。该参数提供大部分指示性信息。当与其结合使用时Content-Disposition: attachment,它被用作提供给 user.filename 的最终“另存为”对话框的默认文件名*

参数“filename”和“filename *”的区别仅在于“filename *”使用RFC 5987中定义的编码。当“文件名”和“文件名*”都出现在单个标题字段值中时,“文件名*”优于“文件名”,当两者都存在并被理解时。

例子

触发“另存为”对话框的响应:

200 OK
Content-Type: text/html; charset=utf-8Content-Disposition: attachment; filename="cool.html"Content-Length: 22<HTML>Save me!</HTML>

这个简单的 HTML 文件将被保存为常规下载而不是在浏览器中显示。大多数浏览器会建议将其保存在cool.html文件名下(默认情况下)。

HTML 表单的一个示例,使用multipart/form-data使用Content-Disposition标题的格式发布:

POST /test.html HTTP/1.1Host: example.org
Content-Type: multipart/form-data;boundary="boundary"--boundary
Content-Disposition: form-data; name="field1"value1--boundary
Content-Disposition: form-data; name="field2"; filename="example.txt"value2--boundary--

规范

Specification

Title

RFC 7578

Returning Values from Forms: multipart/form-data

RFC 6266

Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)

RFC 2183

Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field

浏览器兼容性

Feature

Chrome

Firefox

Edge

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

兼容性说明

  • Content-Disposition如果提供了参数filenamefilename*参数,Firefox 5 将更有效地处理 HTTP 响应头; 它会查看所有提供的名称,filename*如果有可用的名称,则使用参数,即使filename首先包含参数。以前,将使用第一个匹配参数,从而阻止使用更合适的名称。见错误588781。见还

  • HTML Forms

  • The Content-Type defining the boundary of the multipart body.

  • The FormData interface used to manipulate form data for use in the XMLHttpRequest API.

上一篇:下一篇: