[英]Why I can't get a post request in the controller?
I want to get the body of a post in a controller.我想在 controller 中获取帖子的正文。
Here is my code:这是我的代码:
[HttpPost]
public string GetMsg([FromBody]GetMsgModel GSM)
{
return "";
}
And posted class并贴出 class
public class GetMsgModel {
public string ToUserName { get; set; }
public string FromUserName { get; set; }
public string CreateTime { get; set; }
public string MsgType { get; set; }
public string Content { get; set; }
public string MsgId { get; set; }
}
I added a breakpoint to the GetMsg
and send a post via postman with this XML body:我在GetMsg
中添加了一个断点,并通过 postman 使用此 XML 正文发送帖子:
<xml>
<ToUserName>123</ToUserName>
<FromUserName>456</FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType>789</MsgType>
<Content>000</Content>
<MsgId>1234567890123456</MsgId>
</xml>
Well, the breakpoint does not run at all.好吧,断点根本不运行。
What's wrong with this?这有什么问题? There is another HttpGet
method in the same controller and it works well.在同一个 controller 中还有另一个HttpGet
方法,它运行良好。 It seems it is not the problem of the controller yet.似乎还不是 controller 的问题。
If you're using Net Core Add to Statup.cs如果您使用的是 Net Core 添加到 Statup.cs
services.AddXmlSerializerFormatters();
And the XML should be XML 应该是
<GetMsgModel>
<ToUserName>123</ToUserName>
<FromUserName>456</FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType>789</MsgType>
<Content>000</Content>
<MsgId>1234567890123456</MsgId>
</GetMsgModel>
Hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.