Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Created May 14, 2013 20:23
Show Gist options
  • Select an option

  • Save darrelmiller/5579206 to your computer and use it in GitHub Desktop.

Select an option

Save darrelmiller/5579206 to your computer and use it in GitHub Desktop.
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