Hello,
I wonder how to insert request/response JSON messages into database in delegatinghandler?
any help would be great.
- public class LogRequestAndResponseHandler : DelegatingHandler
- {
- protected override async Task
SendAsync( - HttpRequestMessage request, CancellationToken cancellationToken)
- {
- // log request body
- string requestBody = await request.Content.ReadAsStringAsync();
- Trace.WriteLine(requestBody);
- // let other handlers process the request
- var result = await base.SendAsync(request, cancellationToken);
- if (result.Content != null)
- {
- // once response body is ready, log it
- var responseBody = await result.Content.ReadAsStringAsync();
- Trace.WriteLine(responseBody);
- }
- return result;
- }
- }

Jefferson S. MottaRank #207 · 11.7K reputationPosted Feb 9, 2019, 2:19 AM EST
RaysefoRank #4,173 · 360 reputationPosted Feb 9, 2019, 10:39 PM EST
Jefferson S. MottaRank #207 · 11.7K reputationPosted Feb 11, 2019, 4:58 AM EST
RaysefoRank #4,173 · 360 reputationPosted Feb 11, 2019, 6:31 AM EST