【发布时间】:2011-07-03 00:20:37
【问题描述】:
我正在尝试使用 RestSharp 来使用 Web 服务。到目前为止,一切都很顺利(为 John Sheehan 和所有贡献者干杯!)但我遇到了障碍。假设我想以已经序列化的形式(即,作为字符串)将 XML 插入到我的 RestRequest 的正文中。是否有捷径可寻? .AddBody() 函数似乎在幕后进行序列化,所以我的字符串正在变成<String />。
非常感谢任何帮助!
编辑:要求提供我当前代码的示例。见下文--
private T ExecuteRequest<T>(string resource,
RestSharp.Method httpMethod,
IEnumerable<Parameter> parameters = null,
string body = null) where T : new()
{
RestClient client = new RestClient(this.BaseURL);
RestRequest req = new RestRequest(resource, httpMethod);
// Add all parameters (and body, if applicable) to the request
req.AddParameter("api_key", this.APIKey);
if (parameters != null)
{
foreach (Parameter p in parameters) req.AddParameter(p);
}
if (!string.IsNullOrEmpty(body)) req.AddBody(body); // <-- ISSUE HERE
RestResponse<T> resp = client.Execute<T>(req);
return resp.Data;
}
【问题讨论】:
-
您当前的代码是什么样的?你在哪里有问题?
-
抱歉,直到现在才看到这个。你可能想要 AddParameter() 。如果这不是您想要的,请发布到 google 组,并附上您尝试实现的带有 params + xml 的正文示例。 groups.google.com/group/restsharp