如何使用RestSharp发布www-form-urlencoded内容类型数据并接受json?

时间:2017-08-17 03:53:35

标签: c# asp.net-mvc restsharp dotnet-httpclient

小提琴设置:

地址

http://localhost:8080/lzp/servRoot(帖子)

接头

User-Agent: Fiddler Host: localhost:8080 Content-Length: 86 Content-Type: application/x-www-form-urlencoded

RequestBody className=com.lzp.service.UserInfoService&methodName=login&user_name=123&user_pwd=123

并回复

HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Access-Control-Allow-Origin: * Content-Type: text/json;charset=gbk Transfer-Encoding: chunked {"msg":false}

使用fiddler返回{"msg":false}

enter image description here

以下是使用RestSharp的代码。

RestClient client = new RestClient("http://localhost:8080");
RestRequest request = new RestRequest("lzp/servRoot", Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("className", "com.lzp.service.UserInfoService");
request.AddParameter("methodName", "login");
request.AddParameter("user_name", "123");
request.AddParameter("user_pwd", "123");
var response = client.Execute<TestResultModel>(request);
var res = response.Data;

TestResultModel

public class TestResultModel
{
   public string msg { get; set; }
}

为什么我无法反序列化响应数据?enter image description here

0 个答案:

没有答案