HTTP頭之Content-Disposition

Content-Disposition

含義

指示回覆的內容 瀏覽器要以何種形式展示

  • 是以內聯的形式即網頁或者頁面的一部分)
  • 還是以附件的形式下載並保存到本地

multipart/form-data類型的應答消息體中Content-Disposition消息頭可以被用在multipart消息體的子部分中,用來給出其對應字段的相關信息

語法

作爲消息主體中的消息頭

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

作爲multipart body中的消息頭

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

filename*

“filename” 和 “filename*” 兩個參數的唯一區別在於,“filename*“採用了 RFC 5987 中規定的編碼方式。當"filename” 和 “filename*” 同時出現的時候,應該優先採用"filename*”,假如二者都支持的話。

示例

200 OK
Content-Type: text/html; charset=utf-8
Content-Disposition: attachment; filename="cool.html"
Content-Length: 22

<HTML>Save me!</HTML>
POST /test.html HTTP/1.1
Host: 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章