4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
何时使用HTTP 412错误回应? - IT屋-程序员软件开发技术分享社区
来自 : www.it1352.com/7414...html 发布时间:2021-03-25

It is unclear to me when you should and should not return a HTTP 412: Precondition Failed, error for a web service? I am thinking of using it when validating data. For example, if a client POST\'s XML data and that data is missing a required data element, then responding with a 412 and a description of the error.

Does that align with the spirit of responding with an HTTP 412, or should something else be used (e.g. another http error code or web application exception)?

解决方案

If you look at RFC 2616 you\'ll see a number of request headers that can be used to apply conditions to a request:

If-MatchIf-Modified-SinceIf-None-MatchIf-RangeIf-Unmodified-Since

These headers contain \'preconditions\', allowing the client to tell the server to only complete the request if certain conditions are met. For example, you use a PUT request to update the state of a resource, but you only want the PUT to be actioned if the resource has not been modified by someone else since your most recent GET.

The response status code 412 (Precondition Failed) is typically used when these preconditions fail.

Your example sounds like an invalid request (i.e. the client has submitted data that is invalid because of missing values). A status code of 400 (Bad Request) is more appropriate here IMO.


2017年9月28日For example, if a client POST's XML data and that data is missing a required data element, then responding with a 412 and a description of t...web-services,http,exception,rest,程序员,软件开发,软件编程,IT资讯,软件开发工具,教程下载,技术社区,exception,error When is it appropriate to respond with a HTTP 412 error?When is it appropriate to respond with a HTTP 412 error?(何时使用HTTP 412错误回应?) - IT屋-程序员软件开发技术分享社区何时使用HTTP 412错误回应?

本文链接: http://elementis412.immuno-online.com/view-771028.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616