我有一个API端点如下:
[HttpPost]
public async Task<IActionResult> Post([FromBody]Create command)
{
await DispatchAsync(command);
return Created($"Server/{command.Id}", null);
}
public class Create
{
public string Ip { get; set; }
public string Fqdn { get; set; }
public string Comments { get; set; }
public bool IsActive { get; set; }
public string AddBy { get; set; }
public DateTime AddDate { get; set; }
public string LastUpdateBy { get; set; }
public DateTime LastUpdateDate { get; set; }
}
现在,我想测试是在SOAPUI还是RESTClient(Mozilla扩展)中。我的问题是,当我将POST设置为:
"Create" :
{
"Ip": "123",
"Fqdn": "123",
"Comments": "123",
"IsActive": "TRUE",
"AddBy": "test",
"AddDate": "2017-01-01",
"LastUpdateBy": "test",
"LastUpdateDate": "2017-01-01"
}
在调试模式下,传递给端点的Create对象为null。知道POST应该怎么样?
答案 0 :(得分:1)
尝试删除&#34;创建:&#34;部分。 刚发布在json下面:
{
"Ip": "123",
"Fqdn": "123",
"Comments": "123",
"IsActive": "TRUE",
"AddBy": "test",
"AddDate": "2017-01-01",
"LastUpdateBy": "test",
"LastUpdateDate": "2017-01-01"
}
此外,请确保您正在设置&#34;内容类型&#34; as&#34; application / json&#34;在您的请求标题中。