gpt4 book ai didi

请求中未接受的 Content-Type 的 HTTP 状态代码

转载 作者:可可西里 更新时间:2023-11-01 15:04:08 24 4
gpt4 key购买 nike

对于某些资源,我的 RESTful 服务器只接受以 JSON 对象作为内容主体的 PUTPOST 请求,因此需要 Content-Type application/json 而不是 application/x-www-form-urlencodedmultipart/form-data 或其他任何内容。

格式错误的 JSON(或缺少格式的 JSON)返回 400,其中错误消息直接取自 JSON 解析器引发的异常,用于调试目的。

哪个 HTTP 错误代码表示客户端发送了一个 Not Acceptable Content-Type 请求,即使服务器可以在技术上解析请求内容?

最佳答案

根据此列表,它可能是 415 Unsupported Media Type:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16 .

第三方编辑

来自当前RFC9110 HTTP Semantics

The 415 (Unsupported Media Type) status code indicates that the originserver is refusing to service the request because the content is in aformat not supported by this method on the target resource.

The format problem might be due to the request's indicatedContent-Type or Content-Encoding, or as a result of inspecting thedata directly.

If the problem was caused by an unsupported content coding, theAccept-Encoding response header field (Section 12.5.3) ought to beused to indicate which (if any) content codings would have beenaccepted in the request.

On the other hand, if the cause was an unsupported media type, theAccept response header field (Section 12.5.1) can be used to indicatewhich media types would have been accepted in the request.

来源RFC9110 - 415 unsupported media type

关于请求中未接受的 Content-Type 的 HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11973813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com