HTTP 406和415错误代码(HTTP 406 and 415 error codes)

编程入门 行业动态 更新时间:2024-10-25 23:22:56
HTTP 406和415错误代码(HTTP 406 and 415 error codes)

我正在编写一个仅接受json的Web服务,并且只输出json。

所以我需要返回适当的状态码,如果请求了其他任何格式。

看来我有两个选择:

406 - 不可接受 415 - 不支持的介质类型

如果有人能够启发我关于两个代码的语义,这将是巨大的。

I am writing a web service that accepts only json, and also outputs only json.

So I need to return the appropriate status code if any other format is requested.

It appears that I have two choices:

406 - Not Acceptable 415 - Unsupported Media Type

It would be great if someone could enlighten me as to the semantics of the two codes.

最满意答案

406由服务器返回,当它不能基于接受请求头(即它们有一个Accept标头,它们声明他们想要XML)进行响应时。

当请求中发送的实体(POST或PUT中的内容)具有不受支持的媒体类型(即,它们发送XML)时,服务器返回415。

所以.. 406当你不能发送他们想要什么,415当他们发送你不想要的。

希望有帮助!

406 is returned by the server when it can't respond based on accepting the request headers (ie they have an Accept header which states they only want XML).

415 is returned by the server when the entity sent in a request (content in a POST or PUT) has an unsupported mediatype (i.e. they sent XML).

so.. 406 when you can't send what they want, 415 when they send what you don't want.

Hope that helps!

更多推荐

本文发布于:2023-07-17 10:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   HTTP   codes   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!