gpt4 book ai didi

c# - 如何从 WebAPI 中的 [FromBody] 属性获取复杂数据

转载 作者:行者123 更新时间:2023-11-30 23:34:08 27 4
gpt4 key购买 nike

当我尝试发送请求“http://localhost:1234/api/case/create?signature=123456”时来自 Postman(谷歌扩展)在正文请求中使用“表单数据”,我收到错误:

“消息”:“此资源不支持请求实体的媒体类型‘multipart/form-data’。”,"ExceptionMessage": "没有 MediaTypeFormatter 可用于从媒体类型为 'multipart/form-data' 的内容中读取类型为 'Case' 的对象。",“异常类型”:“System.Net.Http.UnsupportedMediaTypeException”。

我的行动:

    [Route("create")]
public object Create([FromBody]Case newCase, string signature)
{
var member = _memberService.GetUserByToken(signature);
if (member != null)
{
var caseId = _caseService.Add(newCase, member);

return Ok(new { caseId });
}

return NotFound();
}

最佳答案

你应该在 Postman 中添加标题 Content-Type: application/json

enter image description here

关于c# - 如何从 WebAPI 中的 [FromBody] 属性获取复杂数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33567171/

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