【发布时间】:2015-01-22 00:11:39
【问题描述】:
我需要发出一个 REST 请求并传递一个具有 XElement 类型属性的对象。
对象:
public class Test
{
public string Property1 {get;set;}
public XElement PropertyXml {get;set;}
}
代码:
var testObj = new Test();
testObj.Property1 = "value";
testObj.PropertyXml = new XElement("test");
var level1 = new XElement("level1", "value111");
testObj.PropertyXml.Add(level1);
var client = new RestClient();
client.BaseUrl = new Uri(string.Format(_url));
var rRequest = new RestRequest(_address, Method.POST);
rRequest.RequestFormat = DataFormat.Json;
rRequest.AddBody(testObj);
var response = client.Execute(rRequest);
我在调用 AddBody 的那一行得到一个“System.StackOverflowException”。 PS 我可以使用 HttpClient(我使用 PostAsJsonAsync 方法)而不是 Restsharp 传递一个 Test 对象。
任何想法都将不胜感激..
【问题讨论】:
-
您使用的是哪个版本的restsharp?如果您使用高于 103 的版本,则需要使用
rRequest.JsonSerializer = new JsonSerializer();将 JSON 序列化程序设置回 JSON.net,其中来自 github.com/restsharp/RestSharp/blob/…
标签: restsharp