Created
November 2, 2015 02:18
-
-
Save weitzhandler/ff9daee7dce835296a00 to your computer and use it in GitHub Desktop.
This file contains 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
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