Last active
March 29, 2017 18:26
-
-
Save hprez21/ea90075eeded34882642d5ab32e0b20a to your computer and use it in GitHub Desktop.
Xamarin.Forms Http Helper class to call any Rest Web Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Se requiere tener instalado los paquetes de nuget: | |
//Install-Package Microsoft.Net.Http | |
//Install-Package Newtonsoft.Json | |
public class HttpHelper<T> | |
{ | |
public async Task<T> GetRestServiceDataAsync(string serviceAddress) | |
{ | |
var client = new HttpClient(); | |
client.BaseAddress = new Uri(serviceAddress); | |
var response = await client.GetAsync(client.BaseAddress); | |
response.EnsureSuccessStatusCode(); | |
var jsonResult = response.Content.ReadAsStringAsync(); | |
var result = JsonConvert.DeserializeObject<T>(jsonResult.Result); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment