可以将charset参数与http / 1.1中的application / json内容类型一起使用? [英] Can charset parameter be used with application/json content type in http/1.1?

查看:341
本文介绍了可以将charset参数与http / 1.1中的application / json内容类型一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,它是有效的ajax请求

$.ajax({
    type: "POST",
    url: "SomePage.aspx/GetSomeObjects",
    contentType: "application/json; charset=utf-8",
    ...
});

这是有时用作示例,或者软件可以显式字符集

rfc 4627应用程序/ json媒体类型说,它不接受第6节中的任何参数:

The rfc 4627 for application/json media type says that it doesn't accept any parameters in section 6:

The MIME media type for JSON text is application/json.

Type name: application

Subtype name: json

Required parameters: n/a

Optional parameters: n/a

可以解释为字符集不应该与application / json一起使用

第3节建议
表示没有必要指定charset:

And section 3 suggests that it is not necessary to specify charset:

JSON text SHALL be encoded in Unicode.  The default encoding is
UTF-8.

Since the first two characters of a JSON text will always be ASCII
characters [RFC0020], it is possible to determine whether an octet
stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
at the pattern of nulls in the first four octets.

        00 00 00 xx  UTF-32BE
        00 xx 00 xx  UTF-16BE
        xx 00 00 00  UTF-32LE
        xx 00 xx 00  UTF-16LE
        xx xx xx xx  UTF-8

,因为UTF-8,16,32编码可以被拒绝从内容。为什么说UTF-8是默认的?在rfc中没有指定选择其他字符编码的方式,并且无论如何都可以确定编码。或者有支持Unicode的其他(不是UTF-8,16,32)字符编码?

because UTF-8,16,32 encodings can be infered from the content. Why does it say that UTF-8 is default? The way to choose other character encoding is not specified in the rfc and the encoding can be found deterministically anyway. Or are there other (not UTF-8,16,32) character encodings that support Unicode?

有人认为可以使用字符集


不同意您必须必须删除的评估。 RFC 2046
声明除了文本的子类型之外的其他媒体类型可以选择
使用在此定义的charset参数,其表示
不存在对
应用程序类型的charset参数。此外,RFC 2045规定MIME
实现必须忽略任何不是
识别的名字的参数。因此,假设它的存在造成了任何危害
是不合理的。

I disagree with your assessment that it must be dropped. RFC 2046 states that "other media types than subtypes of "text" might choose to employ the charset parameter as defined here," which indicates that there is no restriction on the presence of the charset parameter on application types. Additionally, RFC 2045 states that "MIME implementations must ignore any parameters whose names they do not recognize." So, it is not reasonable to assume that there is any harm being done by its presence.

May rfc-compliant软件生成内容类型应用程序/ json与charset参数?如果rfc兼容软件接受这样的请求?

May rfc-compliant software generate content type application/json with a charset parameter? Should rfc-compliant software accept such requests?

推荐答案

application / json没有定义charset参数,包括一个。 RFC 2046说的是一般的应用程序类型可以有一个charset参数,如application / xml。但JSON不。

application/json doesn't define a charset parameter, so it is incorrect to include one. What RFC 2046 says is that application types in general could have a charset parameter, such as application/xml. But JSON does not.

这篇关于可以将charset参数与http / 1.1中的application / json内容类型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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