问题描述
服务器代码是
[HttpPost("/<route>/update2")]
public StatusCodeResult UpdatePanel2([FromBody] PanelUpdateReq updateRequest)
{
if (updateRequest == null)
return BadRequest();
return Ok();
}
public enum ZZ
{
A,B
}
public class D
{
public int Index { get; set; }
public string Path1 { get; set; }
public string Path2 { get; set; }
public ZZ DefectType { get; set; }
public double foo { get; set; }
public int bar { get; set; }
}
public class PanelUpdateReq
{
public int Number { get; set; }
public string Path { get; set; }
public List<D> Items { get; set; }
}
我发现当我为 DefectType
枚举使用数字值(即“DefectType”:0)时,请求返回 OK。但是如果我发送字母 "DefectType": "A" 那么服务器无法解析请求并返回一个错误的请求。
这是完整的请求:
{
"Number" : 2738,"Path" : "abc/cd/2738","Items": [
{
"Index" : 1,"Path1" : "some path 1","Path2" : "some path 2","DefectType" : 0,// or "A" which does not work
"foo": 10.0,"bar" : 11
}
]
}
知道这里出了什么问题吗?我在 SO (here's 1 for example) 上查看了多个其他问题,一致认为使用“A”应该有效。
我使用的是 Postman 客户端,如果重要的话,在标题中将内容类型设置为 application/json
。