Created
April 30, 2021 00:52
-
-
Save mr5z/55e4f6961e0247d8f4de0113eaf9c10a to your computer and use it in GitHub Desktop.
:D
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
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