gpt4 book ai didi

asp.net-web-api - 网络 API : Make action parameter mandatory

转载 作者:行者123 更新时间:2023-12-02 03:46:01 25 4
gpt4 key购买 nike

我有一个看起来像这样的 Action :

[HttpPost]
public HttpResponseMessage PostInstantiation(Guid id, [FromBody]Instantiation instantiation)

如果用户对正确的 URL 执行 POST,但没有(/空)正文,则模型验证不会失败,并且实例化参数为 null。我预计它会失败。

处理这种情况的正确方法是什么?

最佳答案

您注意到的是预期行为。如果您确实想检查用户是否发送了空正文,那么您可以检查传入请求的 Content-Length header 。

if(Request.Content.Headers.ContentLength == 0)

关于asp.net-web-api - 网络 API : Make action parameter mandatory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17119360/

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