繁体   English   中英

为什么在 controller 中收不到 post 请求?

[英]Why I can't get a post request in the controller?

我想在 controller 中获取帖子的正文。

这是我的代码:

[HttpPost]
public string GetMsg([FromBody]GetMsgModel GSM)
{
    return "";
}

并贴出 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; }
}

我在GetMsg中添加了一个断点,并通过 postman 使用此 XML 正文发送帖子:

<xml>
  <ToUserName>123</ToUserName>
  <FromUserName>456</FromUserName>
  <CreateTime>1348831860</CreateTime>
  <MsgType>789</MsgType>
  <Content>000</Content>
  <MsgId>1234567890123456</MsgId>
</xml>

在此处输入图像描述

好吧,断点根本不运行。

这有什么问题? 在同一个 controller 中还有另一个HttpGet方法,它运行良好。 似乎还不是 controller 的问题。

如果您使用的是 Net Core 添加到 Statup.cs

services.AddXmlSerializerFormatters();

XML 应该是

<GetMsgModel>
  <ToUserName>123</ToUserName>
  <FromUserName>456</FromUserName>
  <CreateTime>1348831860</CreateTime>
  <MsgType>789</MsgType>
  <Content>000</Content>
  <MsgId>1234567890123456</MsgId>
</GetMsgModel>

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM