我们可以创建自定义HTTP状态codeS? [英] Can we create custom HTTP Status codes?

查看:660
本文介绍了我们可以创建自定义HTTP状态codeS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST和WCF服务,并要发送基于操作的自定义状态code。

I have a REST and WCF service and want to send a custom status code based on the operation.

在一些验证失败,那么我想送HTTP 444,当授权失败,我想发送HTTP 455例

Example when some validation fails then i want to send HTTP 444 and when authorization fails i want to send HTTP 455

现在的问题是我们如何有它验证为SOAP和REST Web服务。

The question is how do we have it validated for both SOAP and REST web services.

在客户端,因为当你从一个WCF服务发送一个HTTP 400/500(使用SOAP)如何做错误code法案的例外是抛出显示状态code中的客户端上。

On the client how does the error code act because when you send a HTTP 400/500 from a WCF Service (using SOAP) an exception is throw on the client showing the status code.

现在,如果我发送一个新的自定义状态code客户机如何处理呢?

Now if i send a new custom status code how does the client handle this?

推荐答案

是的,只要你尊重类 - 那就是成功的2xx,4XX客户端错误等。所以,你可以自定义返回4xx错误codeS(preferably那些未分配),用于自己的应用程序的错误条件。

Yes, as long as you respect the class -- that is, 2xx for success, 4xx for Client error, etc. So you can return custom 4XX error codes (preferably those that are unassigned) for your own application's error conditions.

要从 RFC 2616报价

HTTP状态codeS是可扩展的,HTTP应用程序不需要
     了解全部注册的状态codeS的含义,尽管这种
     理解显然是不可取的。但是,应用程序必须
     了解类中的任何状态code的,由第一指示
     数字,视为等同于任何无法识别的响应
     X00状态$ C $那类C,所不同​​的是一个
     无法识别的反应绝不能缓存。例如,如果一个
     431无法识别的状态code被客户接受,它可以
     安全地假设,有一些错误的请求,
     治疗反应,就好像它已经收到了400状态code。

"HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class, with the exception that an unrecognized response MUST NOT be cached. For example, if an unrecognized status code of 431 is received by the client, it can safely assume that there was something wrong with its request and treat the response as if it had received a 400 status code."

这篇关于我们可以创建自定义HTTP状态codeS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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