问题
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