Why does Header Content-Type for POST request differ between chrome and firefox only in by “UTF-8” vs “utf-8”?

耗尽温柔 提交于 2021-02-07 20:19:41

问题


I am using Flask and Angular JS to process POST request and I am wondering why the Chrome request header has

application/json;charset=UTF-8

compared to FireFox

application/json;charset=utf-8.

Note the difference is only the chrome capitalizes UTF while FireFox doesnt (utf).

This is probably related to SO: MySQL UTF8 for Chrome, UTF8 for IE, but HEADER UTF8 for Chrome and UTF-8 for IE? but I wasn't able to understand completely. I am not using any meta tag in the html, maybe that is the problem?

The reason this is an issue for me is because I had some server side code like this:

if request.method == "POST":
    print(request.headers['Content-Type'])
    if request.headers['Content-Type'] in ['application/json;charset=UTF-8']:

Which only worked for Chrome and not FireFox until I discovered the capitalization issue with UTF vs utf.


回答1:


Either force both sides to uppercase or lowercase to guarantee a match no matter which browser sends it in.

Not sure which function it is so you may have to look it up, but this is good enough to make my point.

if lowercase(request.headers['Content-Type']) in ['application/json;charset=utf-8']:


来源:https://stackoverflow.com/questions/20429427/why-does-header-content-type-for-post-request-differ-between-chrome-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!