Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Created November 7, 2012 02:42
Show Gist options
  • Save darrelmiller/4029298 to your computer and use it in GitHub Desktop.
Save darrelmiller/4029298 to your computer and use it in GitHub Desktop.
public class RequestPreprocessor : DelegatingHandler {
public RequestPreprocessor(HttpMessageHandler handler) {
this.InnerHandler = handler;
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
request.Content.LoadIntoBufferAsync().RunSynchronously();
// Do your stuff!
return base.SendAsync(request, cancellationToken);
}
}
var client = new HttpClient(new RequestPreprocessor(new HttpClientHandler()));
client.PostAsync(new Uri("http://example.org"), new StringContent("Hello World"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment