【问题标题】:Postman POST Doesn't Pass Parameters邮递员 POST 不传递参数
【发布时间】:2016-04-03 09:56:28
【问题描述】:

当我尝试使用 Postman 进行简单的 POST 时,我的 ASP.NET 资源/模型对象的主体值在使用 [FromBody] 时为空。例如,我在邮递员的正文部分设置参数,并通过邮递员使用 POST 调用这个简单的 url:http://example.net/api/product。当我打破我的控制器时,我的模型参数的值为空。

为什么我的参数不能转换成有效的资源体?

【问题讨论】:

    标签: asp.net postman


    【解决方案1】:

    事实证明,我的控制器设置正确,但我没有正确设置 Postman。要将 POST 的数据从 Postman 发送到 ASP.NET 控制器,您必须转到 Postman 中的“正文”选项卡并 1) 输入参数 2)选择“x-www-form-urlencoded”单选按钮 3) 确保您没有在 Headers 选项卡上设置 Accept-Type 。这很重要,因为它将覆盖“x-www-form-urlencoded”Accept-Type,并导致您的模型无法在 ASP.NET 控制器中正确转换。在我的示例中,我将此设置保留为 Accept-Type = application/json,这个错误导致我的模型无法被翻译。

    通过正确设置,我的控制器能够正确地将我的 POST 数据转换为我的模型。

    【讨论】:

      猜你喜欢
      • 2021-10-13
      • 1970-01-01
      • 2020-03-17
      • 2017-08-29
      • 1970-01-01
      • 2014-11-28
      • 2020-05-23
      • 1970-01-01
      • 2017-12-30
      相关资源
      最近更新 更多