How to compose request for REST web method in fiddler

╄→尐↘猪︶ㄣ 提交于 2019-11-30 22:05:49

问题


I am able to call web serivce but name property is not binding.

Fiddler request

POST http://localhost:50399/api/custservice/ HTTP/1.1
User-Agent: Fiddler
Host: localhost: 50399
Content-Length: 28
{ "request": { "name":"test"}}

POST Webmethod

public string Any(CustomerRequest request)
{
  //return details
}

CustomerRequest.cs

public class CustomerRequest 
{
  public string name {get;set;}
}

回答1:


First of all you need to add Content-Type 'application/json' to the request:

POST http://localhost:50399/api/custservice/ HTTP/1.1
User-Agent: Fiddler
Host: localhost: 50399
Content-Type: application/json

Then change your POST data to:

{"name":"test"}

You will be able to access the data using:

public string Any(CustomerRequest request)
{
  return request.name
}

Alternatively using your existing POST data structure create a new class:

public class RequestWrapper
{
  public CustomerRequest request { get; set; }
}

and change your Action method to:

public string Any(RequestWrapper wrapper)
{
  return wrapper.request.name;
}


来源:https://stackoverflow.com/questions/15413101/how-to-compose-request-for-rest-web-method-in-fiddler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!