HTTP 406 和 415 错误代码 [英] HTTP 406 and 415 error codes

查看:38
本文介绍了HTTP 406 和 415 错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个只接受 json,也只输出 json 的 web 服务.

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.

看来我有两个选择:

  1. 406 - 不可接受
  2. 415 - 不支持的媒体类型

如果有人能启发我了解这两个代码的语义,那就太好了.

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

推荐答案

406 由服务器返回,当它无法基于接受请求标头做出响应时(即,它们有一个 Accept 标头,说明它们only 想要 XML).

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).

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

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).

所以.. 406 当你不能发送他们想要的东西时,415 当他们发送你不想要的东西时.

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

希望有帮助!

这篇关于HTTP 406 和 415 错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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