本文介绍了如何在Fiddler中编写对REST Web方法的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以调用网络服务,但name属性没有绑定.

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

提琴手的请求

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

POST网络方法

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

CustomerRequest.cs

CustomerRequest.cs

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

推荐答案

首先,您需要在请求中添加Content-Type'application/json':

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

然后将您的POST数据更改为:

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
}

或者使用现有的POST数据结构创建一个新类:

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

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

并将您的Action方法更改为:

and change your Action method to:

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

这篇关于如何在Fiddler中编写对REST Web方法的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:47