如何使用HTTP 412代码 [英] how to use HTTP 412 code

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

问题描述

我正在开发一个RESTful Web服务。 Web服务从客户端接收XML,它应该拒绝一些包含与我们的业务逻辑相关的错误的错误请求(例如,支付值低于最小值)。如果拒绝请求,则会在响应XML(http响应主体内)中写入自定义错误代码和错误消息。我还想在状态行中返回​​HTTP代码,因此客户端可以立即识别拒绝,而无需查看当前的响应。有些人建议使用HTTP代码412,但是通过查看HTTP 412的定义:



412前提条件失败



在服务器上测试时,一个或多个请求标头字段中给出的前提条件被评估为false。此响应代码允许客户端在当前资源元信息(标题字段数据)上放置先决条件,从而防止将请求的方法应用于非预期的资源。



<我不太明白它代表什么。有人可以解释412的适当用法吗?或者在这种情况下是否有更好的选择?

解决方案

它用于条件请求: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p4-conditional -25.html



您可能需要查看422或409.


I am developing a RESTful web service. The web service receives XML from clients, it should reject some bad requests containing some error related to our business logic(say, the payment value below a minimum value). If rejecting request, a customised error code and error message will be written in a response XML(inside http response body). I also want to return a HTTP code in the status line, so client can recognize rejection right away without looking into the response boday. Some people suggest using HTTP code 412, however by looking at the definition of HTTP 412:

412 Precondition Failed

The precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. This response code allows the client to place preconditions on the current resource metainformation (header field data) and thus prevent the requested method from being applied to a resource other than the one intended.

I don't quite understand what it represents for. Could someone explain the appropriate usage of 412 please? or in this case are there any better choices?

解决方案

It's for use with conditional requests: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p4-conditional-25.html.

You may want to look at 422 or 409 instead.

这篇关于如何使用HTTP 412代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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