Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with result.Content.ReadAsStringAsync() in a DelegatingHandler #349

Open
jefflaia opened this issue Aug 9, 2017 · 0 comments

Comments

@jefflaia
Copy link

jefflaia commented Aug 9, 2017

I add a DelegatingHandler for logging in my current MVC API. I tried to use i18n for multiple languages support. But the response content is not translated.it returns original string with [[[]]]. My DelegatingHandler code like follows:

public class LogRequestResponseHandler : DelegatingHandler
{
...
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// log request body
...

        // let other handlers process the request
        var result = await base.SendAsync(request, cancellationToken);

        // log response body
        string responseBody = string.Empty;
        if (result?.Content != null)
        {
            responseBody = await result.Content.ReadAsStringAsync();
        }
        _logger.Debug($"{request.RequestUri}, {request.Method.Method}, Status: {result.StatusCode} Success: {result.IsSuccessStatusCode}, Response body: {responseBody}");

        return result;
    }
}

it can work when I commented result.Content.ReadAsStringAsync() in above code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant