【发布时间】:2020-01-28 17:32:13
【问题描述】:
在 ASP.NET Core 3.0 中对 ApiController 使用 [FromBody] 字符串内容会返回验证错误:
{"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title":"One or more validation errors occurred.",
"status":400,
"traceId":"|9dd96d96-4e64bafba4ba0245.",
"errors":{"$":["The JSON value could not be converted to System.String. Path: $ | LineNumber: 0 | BytePositionInLine: 1."]}}
当客户端使用 content-type 发布数据时:application/json
如何在 .NET Core 3.0 的 api 控制器中将原始 json 数据作为字符串获取?无需客户端更新其内容类型?
【问题讨论】:
-
这在 .net core 2.1 中有效吗?发布您的 json 示例。
-
我决定只使用 StreamReader 并自己阅读 Request.Body。它是一个新项目,在 2.1 上还没有 testet,但过去可能将正文绑定到 JToken 而不是字符串。
标签: c# json asp.net-core asp.net-core-mvc asp.net-core-3.0