我注意到有时请求的 content-type
header (例如,由 Firefox 发出)不仅包含有关 MIME 类型的信息,还包含有关编码的信息。
例如,当使用 AJAX 而不是发送 JSON 时
application/json
(我所期望的)Firefox 发送:
application/json; charset=UTF-8
我对此行为有很多疑问:
- 还可能发生哪些其他“参数”(或“选项”,或任何您所说的
字符集
值)? application/json
是否始终排在第一位,或者这些值可能以随机顺序出现(即,它也可以是charset=UTF-8; application/json
) ?- 分隔符总是
;
吗? - 测试特定 MIME 类型的规范方法是什么?显然,仅比较标题是行不通的。有什么提示吗?有没有比
contentType === 'application/json || 更好的东西contentType.startsWith('application/json;')
?
PS:对于问题#4,我创建了一个单独的问题。请参阅Get an entire string or a substring, depending on a specific character
最佳答案
请参阅HTTP 1.1 RFC
3.7 Media Types
HTTP uses Internet Media Types [17] in the Content-Type (section 14.17) and Accept (section 14.1) header fields in order to provide open and extensible data typing and type negotiation.
media-type = type "/" subtype *( ";" parameter ) type = token subtype = token Parameters MAY follow the type/subtype in the form of attribute/value pairs (as defined in section 3.6).
所以
- 没有固定的可能值列表
- 是的,类型应该放在第一位
- 分隔符为
;
关于javascript - 请求的 content-type header 包含的内容多于 MIME 类型,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26947564/