Web API post 请求:Post([FromBody] JObject value) errors:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|bc8869df-4a1421febb7b9f25.",
"errors": {
"$": [
"The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[Newtonsoft.Json.Linq.JToken]. Path: $ | LineNumber: 1 | BytePositionInLine: 15."
]
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddControllers();
services.AddControllers().AddNewtonsoftJson();//注册服务
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
}
本文探讨了在使用WebAPI进行POST请求时遇到的具体错误,包括JSON转换问题和验证错误。详细介绍了错误类型、状态码及跟踪ID,同时提供了配置服务的代码示例,涉及跨域、控制器和Newtonsoft JSON的添加。
347

被折叠的 条评论
为什么被折叠?



