Skip to content

Instantly share code, notes, and snippets.

@mr5z
Created April 30, 2021 00:52
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 mr5z/55e4f6961e0247d8f4de0113eaf9c10a to your computer and use it in GitHub Desktop.
Save mr5z/55e4f6961e0247d8f4de0113eaf9c10a to your computer and use it in GitHub Desktop.
:D
class LoggingInterceptor : HttpClientHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Debug.Log("Request {0}", request.RequestUri.PathAndQuery);
if (request.Content != null)
{
var contentRequest = await request.Content.ReadAsStringAsync();
}
var response = await base.SendAsync(request, cancellationToken);
Debug.Log("Response {0} ({1}) {2}", request.RequestUri.PathAndQuery, (int)response.StatusCode, response.StatusCode);
return response;
}
}
// and use it like below
var httpClient = new HttpClient(new LoggingInterceptor())
{
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment