我想得到休息锐利 https://github.com/restsharp/RestSharp享受我拥有的令人安心的服务。一切似乎都工作正常,除了当我的对象通过POST
包含一个列表(在这种特殊情况下是一个列表string
).
我的对象:
public class TestObj
{
public string Name{get;set;}
public List<string> Children{get;set;}
}
当这被发送到服务器时Children
属性作为包含内容的字符串发送System.Collections.Generic.List`1[System.String]
.
这就是我发送对象的方式:
var client = new RestClient();
var request = new RestRequest("http://localhost", Method.PUT);
var test = new TestObj {Name = "Fred", Children = new List<string> {"Arthur", "Betty"}};
request.AddObject(test);
client.Execute<TestObj>(request);
我是否做错了什么,或者这是 RestSharp 中的错误? (如果有什么不同的话,我使用的是 JSON,而不是 XML。)
这取决于您所使用的服务器,但如果您使用的是 ASP.NET Web API 控制器(可能还有其他服务器端技术),则如果您循环添加集合中的每个项目,它将起作用:
foreach (var child in test.Children)
request.AddParameter("children", x));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)