我注意到有时请求的content-type
标头(例如,由Firefox制作)不仅包含有关MIME类型的信息,还包含有关编码的信息。
,例如,使用AJAX而不是
发送JSON时application/json
(我的预期)Firefox发送:
application/json; charset=UTF-8
我对此行为有很多疑问:
charset
的值)?application/json
总是先出现,或者值是否以随机顺序出现(也就是charset=UTF-8; application/json
}?;
?contentType === 'application/json || contentType.startsWith('application/json;')
更好的东西?PS:对于问题#4,我创建了一个单独的问题。见Get an entire string or a substring, depending on a specific character
答案 0 :(得分:1)
请参阅HTTP 1.1 RFC
3.7媒体类型
HTTP使用Content-Type中的Internet媒体类型[17](部分 14.17)和Accept(第14.1节)标题字段,以提供开放和可扩展的数据类型和类型协商。
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).
所以
;