I have a url that contains valid xml, but unsure on how I could retrieve this with RestClient. I thought I could just download the string and then parse it like I allready to with WebClient.
Doing:
public static Task<String> GetLatestForecast(string url)
{
var client = new RestClient(url);
var request = new RestRequest();
return client.ExecuteTask<String>(request);
}
Makes VS cry about that ‘string’ must be a non-abstract type with a public parameterless constructor.
See 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;
}
}
}
Thanks to Claus Jørgensen btw for a awesome tutorial on Live Tiles!
I just want to download the string as I already have a parser waiting for it to parse it 🙂
If all you want is a string, just use this approach instead: