简体   繁体   English

如何在fiddler中撰写REST Web方法的请求

[英]How to compose request for REST web method in fiddler

I am able to call web serivce but name property is not binding. 我可以调用web服务但名称属性不绑定。

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 POST Webmethod

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

CustomerRequest.cs CustomerRequest.cs

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

First of all you need to add Content-Type 'application/json' to the request: 首先,您需要在请求中添加Content-Type'application / json':

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: 然后将您的POST数据更改为:

{"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: 或者,使用现有的POST数据结构创建一个新类:

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

and change your Action method to: 并将您的Action方法更改为:

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

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

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