简体   繁体   English

对于多部分数据请求,应在Content-Type标头中使用哪个分隔符?逗号或分号?

[英]Which separator should be used in the Content-Type header for a multipart data request? Comma or Semicolon?

Should the Content-Type header in a REST API web request be formatted with a comma as in RFC 1867 : 如果在RFC 1867中使用逗号格式化REST API Web请求中的Content-Type标头:

Content-type: multipart/form-data, boundary=AaB03x

Or with a semicolon, as in RFC 1049 and RFC 2045 : 或者使用分号,如RFC 1049RFC 2045

Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p

It's really all just a simple mistake and the ; 这真的只是一个简单的错误而且; is correct. 是正确的。

RFC 1867 was an experimental definition. RFC 1867是一个实验性定义。 All subsequent definitions have corrected this mistake. 所有后续定义都纠正了这个错误。 For example: 例如:

  • RFC 2388 explicitly replaces 1867 and refers to HTML 40 for the (correct) definition of the separator. RFC 2388明确替换了1867,并引用HTML 40来定义分隔符(正确)。
  • RFC 7231 explicitly refers to 2388 as the definition to use in HTTP/1.1. RFC 7231明确地将2388称为在HTTP / 1.1中使用的定义。

And finally... there is also an official correction to RFC 1867 to make it use the correct delimiter. 最后......还有一个对RFC 1867的官方更正 ,以使其使用正确的分隔符。

Rely on the newest RFC: 7231, section 3.1.1.1 says: 依靠最新的RFC:7231,第3.1.1.1节说:

media-type = type "/" subtype *( OWS ";" OWS parameter )

This leaves no room for interpretations or custom formats. 这为解释或自定义格式留下了空间。

Unfortunately, it's not the first case I see, when several RFCs conflicts one with another. 不幸的是,这并不是我看到的第一种情况,当时有几个RFC相互冲突。

In this exact case, RFC 1049 is explicitly cover Content-type header. 在这种情况下,RFC 1049明确涵盖了Content-type标头。 RFC 2045 is referencing to RFC 1049. Moreover, RFC 2045 dated November 1996, so it's latest one. RFC 2045引用了RFC 1049.此外,RFC 2045发布于1996年11月,所以它是最新版本。

Opposite case is covered in RFC 1867 very briefly. RFC 1867非常简短地介绍了相反的情况。

So, I suggest to use semi-colon. 所以,我建议使用分号。

Note that your two conflicting examples aren't really contradictory. 请注意,您的两个相互矛盾的示例并不是真正矛盾的。 The first, RFC-1867, defines extensions to HTML. 第一个是RFC-1867,它定义了HTML的扩展。 The other two, RFC-1049 and RFC-2045, both define extensions to the Internet Mail protocol. 另外两个RFC-1049和RFC-2045都定义了Internet邮件协议的扩展。

For a REST API, I would probably go with RFC-1867, which was designed with HTML over HTTP in mind, as opposed to the other two, which were designed with RFC-822-based emails over SMTP/POP/IMAP in mind. 对于REST API,我可能会使用RFC-1867,它是基于HTTP设计的,而不是其他两个,它们是基于RFC / 822的电子邮件设计的,基于SMTP / POP / IMAP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM