当用户提供的数据在 Web 服务中验证失败时返回哪个 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.
Which one would you use?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
400 更正确,即请求包含无效数据。 403 意味着某种权限错误,即请求格式正确且正确,但操作不被允许。如果我正在编写代码来使用 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.