406格式不可接受的有效载荷? [英] Format for 406 Not Acceptable payload?

查看:92
本文介绍了406格式不可接受的有效载荷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在406不可接受的响应中:

In a 406 Not Acceptable response:

服务器应生成包含可用列表的有效负载 表示特征和相应的资源标识符 用户或用户代理可以从中选择最合适的一种. 用户代理可以自动从中选择最合适的选择 那个清单.但是,本规范未定义任何标准 进行自动选择,如RFC7231第6.4.1节所述.

The server SHOULD generate a payload containing a list of available representation characteristics and corresponding resource identifiers from which the user or user agent can choose the one most appropriate. A user agent MAY automatically select the most appropriate choice from that list. However, this specification does not define any standard for such automatic selection, as described in RFC7231 Section 6.4.1.

可用表示特征和相应资源标识符的列表 "的首选格式吗?

Is there a preferred format for that "list of available representation characteristics and corresponding resource identifiers"?

我可以发送如下答复:

{ Acceptable: ["application/json", "application/pdf"] }

但是随后我假设406有效负载(在这种情况下为JSON)具有默认的Content-Type.

But then I am assuming a default Content-Type for the 406 payload (JSON in this case).

或者我应该发送一个非常简单的,几乎无格式的有效载荷,例如:

Or should I send a very simple, almost format-less, payload like:

application/json,application/pdf

推荐答案

"可用表示特征和相应资源标识符的列表" 是否有首选格式?

Is there a preferred format for that "list of available representation characteristics and corresponding resource identifiers"?

对于这种有效负载没有标准.

There's no standard for such payload.

您可以选择用户代理可以轻松解析的任何格式.实际上,JSON或文本都应该没问题:

You could choose any format that can be easily parsed by the user agent. In practice, both JSON or text should be fine:

{ "acceptable" : [ "application/json", "application/pdf" ] }

application/json,application/pdf

请参阅以下 6.4.1 部分中的以下引用 RFC 7231 . ietf.org/html/rfc7231#section-6.5.6"rel =" nofollow noreferrer> 406 状态码定义:

See the following quote from the section 6.4.1 of the RFC 7231, which is referenced in the 406 status code definition:

[...]不会定义自动选择的特定格式 此规范,因为HTTP尝试保持正交于 有效载荷的定义.实际上,表示是 以易于理解的某种格式提供,被认为可以接受 用户代理,由共享设计或内容确定 协商,或采用某些普遍接受的超文本格式. [...]

[...] A specific format for automatic selection is not defined by this specification because HTTP tries to remain orthogonal to the definition of its payloads. In practice, the representation is provided in some easily parsed format believed to be acceptable to the user agent, as determined by shared design or content negotiation, or in some commonly accepted hypertext format. [...]

来自Mozilla的

MDN Web文档建议关注:

MDN Web Docs from Mozilla suggests the following:

[...]实际上,很少使用此错误:服务器不会使用此错误代码进行响应(该错误代码对于最终用户来说是神秘的且难以修复),而是会忽略相关的标头并提供实际的页面用户.假定即使用户不会完全满意,他们也会更喜欢此代码而不是错误代码. [...]

[...] In reality, this error is very rarely used: instead of responding using this error code, which would be cryptic for the end user and difficult to fix, servers ignore the relevant header and serve an actual page to the user. It is assumed that even if the user won't be completely happy, they will prefer this to an error code. [...]

这篇关于406格式不可接受的有效载荷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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