Skip to content

Instantly share code, notes, and snippets.

@hprez21
Last active March 29, 2017 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hprez21/ea90075eeded34882642d5ab32e0b20a to your computer and use it in GitHub Desktop.
Save hprez21/ea90075eeded34882642d5ab32e0b20a to your computer and use it in GitHub Desktop.
Xamarin.Forms Http Helper class to call any Rest Web Service
//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