0
我有一个包含有效xml的url,但不确定如何使用RestClient检索这个。我想我可以下载这个字符串,然后像我一样使用WebClient进行解析。如何使用RestClient下载XML?
这样做:
public static Task<String> GetLatestForecast(string url)
{
var client = new RestClient(url);
var request = new RestRequest();
return client.ExecuteTask<String>(request);
}
使VS哭关于“串”必须是一个非抽象类型与公共参数构造函数。
见executetask:
namespace RestSharp
{
public static class RestSharpEx
{
public static Task<T> ExecuteTask<T>(this RestClient client, RestRequest request)
where T : new()
{
var tcs = new TaskCompletionSource<T>(TaskCreationOptions.AttachedToParent);
client.ExecuteAsync<T>(request, (handle, response) =>
{
if (response.Data != null)
tcs.TrySetResult(response.Data);
else
tcs.TrySetException(response.ErrorException);
});
return tcs.Task;
}
}
}
由于克劳斯约根森BTW对活的瓷砖一真棒教程!
我只是想下载的字符串作为我已经有一个解析器等待它来分析它:-)