C# 如何在.core(POSTMAN)中的[FromBody](原始)中发布json参数
我在.core3项目中有一个方法C# 如何在.core(POSTMAN)中的[FromBody](原始)中发布json参数,c#,asp.net-core,C#,Asp.net Core,我在.core3项目中有一个方法[Post]。以及: 我将使用带有10个json参数的post: [ { "os": "android", "type": "www", "versionCode": 123, "operand": "fofdr", "forceUpdate": false,
[Post]
。以及:
我将使用带有10个json参数的post:
[
{
"os": "android",
"type": "www",
"versionCode": 123,
"operand": "fofdr",
"forceUpdate": false,
"title": "dsfs",
"message": "fdsf",
"action": "act",
"positiveButton": "btn1",
"negativeButton": "test",
"messageType": "sadad"
}
]
以及:
如何使用POSTMAN将json参数传递给此方法api?这应该与@Christoph Lütjen的提示一起使用:
class MyMessage {
public string Os { get; set; }
public string Type { get; set; }
public int VersionCode { get; set; }
public string Operand { get; set; }
public bool ForceUpdate { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string Action { get; set; }
public string PositiveButton { get; set; }
public string NegativeButton { get; set; }
public string MessageType { get; set; }
}
[HttpPost]
[Route("CreateStartMessage")]
public IActionResult CreateStartMessage([FromBody]MyMessage clientMessage) {
return Ok(resultApi);
}
文档中描述了如何使用邮递员发送json:-但您的json将无法与您的邮件签名一起使用。您没有10个参数,只有一个参数,它是一个对象列表,对象具有属性os、类型。。。您需要创建一个类来建模json结构。clientMessage我定义了谁?danke mein Freund!
class MyMessage {
public string Os { get; set; }
public string Type { get; set; }
public int VersionCode { get; set; }
public string Operand { get; set; }
public bool ForceUpdate { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string Action { get; set; }
public string PositiveButton { get; set; }
public string NegativeButton { get; set; }
public string MessageType { get; set; }
}
[HttpPost]
[Route("CreateStartMessage")]
public IActionResult CreateStartMessage([FromBody]MyMessage clientMessage) {
return Ok(resultApi);
}