Sending asynchronous HTTP GET request and reading JSON request

suggest change
public static async Task<TResult> GetAnsync<TResult>(this Uri uri)
{
    using (var client = new HttpClient())
    {
        var message = await client.GetAsync(uri);

        if (!message.IsSuccessStatusCode)
            throw new Exception();

        return message.ReadAsAsync<TResult>();
    }
}

. . .

public class Result
{
    public double foo { get; set; }

    public string bar { get; set; }
}

var uri = new Uri("http://stackoverflow.com/documentation/c%23/1971/performing-http-requests");
var result = await uri.GetAsync<Result>();

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents