测试接受JSON作为输入的web api

时间:2017-10-31 17:50:09

标签: c# json asp.net-web-api

我正在创建一个web api,它需要接受JSON作为被调用客户端应用程序发送的输入。以下是代码

 public class SetNameController : ApiController
 {
 [HttpPost]
 public async Task<IHttpActionResult> Get([FromBody] CodeDTO.RootObject bCode)
 {
  string Bar_Code = bCode.Barcode.ToString();

  if (Bar_Code == "" || Bar_Code == null)
  { 
   ....
   return OK(response)
 }

这里我不确定客户端应用程序如何调用此Web API,URL可以像http://localhost:41594/api/SetName一样接受JSON?我也可以使用PostMan或Fiddler进行测试吗?

1 个答案:

答案 0 :(得分:2)

指定以下内容:

  • 方法:POST
  • 标题:内容类型

enter image description here

然后,将Body中的有效负载json数据提供为raw:

enter image description here

此外,更改可能导致混淆的操作[Route('yourURL')]的名称。如果您仍然无法点击api,则可以通过使用 map = new google.maps.Map(document.getElementById("map_canvas"), options); map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, icon: '/pin.png', title: data['store_title'] }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); 属性修改操作来使用路径网址,并在邮递员中进行相应更改。