Created
May 14, 2013 20:23
-
-
Save darrelmiller/5579206 to your computer and use it in GitHub Desktop.
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
| using System; | |
| using System.Net.Http; | |
| using System.Threading.Tasks; | |
| namespace SimpleHttpClient | |
| { | |
| class Program | |
| { | |
| private static Uri url = new Uri("http://bing.com/"); | |
| static void Main(string[] args) | |
| { | |
| MakeRequest(); | |
| Console.Read(); | |
| } | |
| private static async Task MakeRequest() | |
| { | |
| var httpClient = new HttpClient(); | |
| try | |
| { | |
| var responseMessage = await httpClient.GetAsync(url); | |
| responseMessage.EnsureSuccessStatusCode(); | |
| var body = await responseMessage.Content.ReadAsStringAsync(); | |
| Console.WriteLine(body); | |
| } | |
| catch (Exception e) | |
| { | |
| Console.WriteLine("Request error" + e.Message); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment