Last active
January 16, 2017 20:14
-
-
Save EricCote/b28efafc07493e89d0b02a1cb3ae2feb to your computer and use it in GitHub Desktop.
WebApi Client
This file contains hidden or 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
| 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