404未找到或错误请求? [英] 404 Not Found or Bad Request?

查看:245
本文介绍了404未找到或错误请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有以下REST调用:

Let's say that we have the following REST call:

GET api/companies/5 

(获取ID为5的公司)

如果公司'5'不存在,我们通常会返回404 Not Found响应.

If company '5' doesn't exist, we would typically return a 404 Not Found response.

但现在,让我们接听此电话:

But now, let's take this call:

GET api/companies/5/invoices/10 

(从公司5获取发票10)

现在,如果公司'5'不存在,我们是否仍返回404 Not Found?或仅在找不到最外面的资源时才返回404(在这种情况下,发票10).

Now, if company '5' doesn't exist, do we still return a 404 Not Found? Or should a 404 only be returned if the outer most resource can not be found (invoice 10, in this case).

Bad Request也许是更好的选择吗?

Would Bad Request perhaps be a better option?

推荐答案

404是您最好的选择.根据HTTP RFC, http://www.ietf.org/rfc/rfc2616.txt,"400错误请求"表示:

404 is your best response. According the HTTP RFC, http://www.ietf.org/rfc/rfc2616.txt, a 400 Bad Request means:

由于语法格式错误,服务器无法理解该请求.

The request could not be understood by the server due to malformed syntax.

其中404指出:

服务器未找到与请求URI匹配的任何内容.

The server has not found anything matching the Request-URI.

整个URI是您的资源标识符,而您没有找到该特定标识符的匹配资源.

The entire URI is your resource identifier, and you're not finding a matching resource for that particular identifier.

这篇关于404未找到或错误请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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