用户提供的数据在Web Service中验证失败时返回哪个Http状态代码? [英] Which Http Status code to return when user provided data fails validation in Web Service?

查看:112
本文介绍了用户提供的数据在Web Service中验证失败时返回哪个Http状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户输入数据并提交数据时,我们使用和XMLHttpRequest将其传递给服务器.但是,如果该数据未能通过验证,我们必须返回400级状态代码.我以为适当的代码应该是403.但是,我的同事不同意,但是不知道使用哪个.

When the user enters data and submits that data, we pass it to the server using and XMLHttpRequest. But, if that data fails validation, we have to return a 400 level status code. I thought the appropriate code would be 403. However, my colleague doesn't agree but doesn't know which to use.

您会使用哪个?

谢谢!

推荐答案

400会更正确,即请求中包含无效数据. 403会暗示某种permision错误,即请求的格式正确且正确,但不允许采取措施.如果我正在编写代码以使用Web服务并且出现403错误,那么我永远不会想到这是因为我发送的是无效数据,这的确会造成混乱.

400 would be more correct, i.e. the request contained invalid data. 403 would imply some kind of permisions error, i.e. the request was well formed and correct but the action was not allowed. If i was writing code to consume a web service and i got a 403 error it would never occur to me that it was because i was sending invalid data, it would be very confusing indeed.

这篇关于用户提供的数据在Web Service中验证失败时返回哪个Http状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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