为什么POST请求的标头内容类型在chrome和firefox之间仅在"UTF-8"中有所不同?对比"utf-8"? [英] Why does Header Content-Type for POST request differ between chrome and firefox only in by "UTF-8" vs "utf-8"?

查看:77
本文介绍了为什么POST请求的标头内容类型在chrome和firefox之间仅在"UTF-8"中有所不同?对比"utf-8"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flask和Angular JS处理POST请求,我想知道为什么Chrome请求标头具有

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

与FireFox相比

application/json; charset = utf-8 .

请注意,区别仅在于Chrome的首字母大写为UTF,而FireFox的不为(utf).

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

这可能与SO有关:

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']:

在我发现 UTF vs utf 的大小写问题之前,仅适用于Chrome,而不适用于FireFox.

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

推荐答案

无论哪个浏览器发送匹配,都强制双方都以大写或小写形式保证匹配.

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']:

这篇关于为什么POST请求的标头内容类型在chrome和firefox之间仅在"UTF-8"中有所不同?对比"utf-8"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆