客户
var request = new RestRequest(Method.POST);request.Resource = "Api/Score";request.RequestFormat = DataFormat.Json;request.AddBody(request.JsonSerializer.Serialize(new { A = "foo", B = "bar" }));RestResponse response = client.Execute(request);Console.WriteLine(response.Content);
服务器
public class ScoreInputModel{ public string A { get; set; } public string B { get; set; }}// Api/Scorepublic JsonResult Score(ScoreInputModel input){ // input.A and input.B are empty when called with RestSharp}
我在这里缺少什么?
request.RequestFormat = DataFormat.Json;request.AddBody(new { A = "foo", B = "bar" }); // uses JsonSerializer
如果你只是想要POST params(它仍然会映射到你的模型,是一个更高效的,因为没有序列化到JSON)做到这一点:
request.AddParameter("A", "foo");request.AddParameter("B", "bar");
联系客服