在asp.net Web API中使用FromBody时,字符串值是Empty [英] string value is Empty when using FromBody in asp.net web api
本文介绍了在asp.net Web API中使用FromBody时,字符串值是Empty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net核心Web API.以下是我的简单post函数,它具有单个字符串参数.问题是当我使用[FromBody]时,字符串保持为空.我正在使用PostMan来测试我的服务.我希望原始数据从客户端传递到我的控制器.在邮递员中,我选择的是RAW类型,我设置标题Content-Type文本/纯文本.Raw Body包含"Hello World"字符串.
I am using asp.net core web api. below is my simple post function which is having a single string parameter. The problem is when I use [FromBody] the string stays null. I am using PostMan to test my service. I want raw data to pass from client to my controller. In Postman I am selecting body type RAW and I set the header Content-Type text/plain. The Raw Body contains Just "Hello World" string.
[HttpPost]
[Route("hosted-services/tokenize-card")]
public IActionResult Test([FromRoute]decimal businessKey,[FromBody] string body)
{
var data = businessKey;
return new JsonResult("Hello World");
}
推荐答案
查看全文