gpt4 book ai didi

rest - 当请求需要先完成另一个请求时,我可以使用 HTTP 响应 424 吗?

转载 作者:可可西里 更新时间:2023-11-01 15:20:15 26 4
gpt4 key购买 nike

例如,我有一个实体层次结构,由于某些问题,我在创建父实体的请求之前收到了创建子实体的请求。

在这种情况下使用代码 424 是否正确?

最佳答案

对此肯定有一些意见的余地。 RFC4918 将 HTTP 状态代码 424 定义为(强调我的):

The 424 (Failed Dependency) status code means that the method could not be performed on the resource because the requested action depended on another action and that action failed. For example, if a command in a PROPPATCH method fails, then, at minimum, the rest of the commands will also fail with 424 (Failed Dependency).

在我看来,这不适合您的情况,因为相关操作尚未发生,而此状态代码似乎表明相关操作已收到但失败。

Julian Rechke 对 409 Conflict 的回答在 RFC2616 中定义为

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.

但是,如果收到此响应的客户端能够解决问题(在这种情况下,创建父级),则您应该只使用此响应。如果情况并非如此,我可能再次从 RFC4918 推荐一个 422 Unprocessable Entity:

The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

或者只是一个很好的老式 400 Bad Request 因为在请求的时间点创建不存在的父项的子项真的没有意义。

关于rest - 当请求需要先完成另一个请求时,我可以使用 HTTP 响应 424 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27286857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com