Skip to content

Instantly share code, notes, and snippets.

@weitzhandler
Created November 2, 2015 02:18
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 weitzhandler/ff9daee7dce835296a00 to your computer and use it in GitHub Desktop.
Save weitzhandler/ff9daee7dce835296a00 to your computer and use it in GitHub Desktop.
namespace ConsoleApplication1
{
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
class Program
{
static void Main(string[] args)
{
Task.Run(async () => { await RunAsync(); }).Wait();
WriteLine("Press any key to finish.");
ReadKey();
}
public static async Task RunAsync()
{
WriteLine("RunAsync called.");
using (var client = new MyHttpClient())
await client.GetAsync("http://www.google.com");
}
}
public class MyHttpClient : HttpClient
{
public MyHttpClient()
: base(new MyHandler())
{
WriteLine("Client instantiated.");
}
public override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
WriteLine("HttpClient.SendAsync");
return base.SendAsync(request, cancellationToken);
}
}
public class MyHandler : HttpClientHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
WriteLine("MyHandler.SendAsync");
return base.SendAsync(request, cancellationToken);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment