Skip to content

Instantly share code, notes, and snippets.

@EricCote
Last active January 16, 2017 20:14
Show Gist options
  • Select an option

  • Save EricCote/b28efafc07493e89d0b02a1cb3ae2feb to your computer and use it in GitHub Desktop.

Select an option

Save EricCote/b28efafc07493e89d0b02a1cb3ae2feb to your computer and use it in GitHub Desktop.
WebApi Client
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.BaseAddress =new Uri("http://localhost:52516/api/abonnement");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("").Result;
if (response.IsSuccessStatusCode)
{
var abonnements = response.Content.
ReadAsAsync<IEnumerable<Abonnement>>().Result;
foreach (Abonnement ab in abonnements)
{
Console.WriteLine(ab.Courriel);
}
}
else
{
Console.WriteLine(
"Error Code : " + response.StatusCode +
"\nMessage : " + response.ReasonPhrase);
}
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment