I just hit post call and i have request and response both. I have method in which i am trying to log request and repose body in my db for that i am just building req and response body.
internal static async Task<string> GetBodyForLoggingAsync(this HttpRequestMessage request)
{
return await GetBodyForLoggingAsync(request.Content);
}
private static async Task<string> GetBodyForLoggingAsync(HttpContent content)
{
if (content == null)
{
return null;
}
string requestBody = null;
var contentType = content.Headers.ContentType;
if (contentType == null || _contentTypesWhereBodyIsLogged.Contains(contentType.MediaType))
{
try
{
Debug.WriteLine(" ---- GETTING BODY CONTENT");
using (var ms = new MemoryStream())
{
try
{
await content.CopyToAsync(ms).ConfigureAwait(false);
ms.Seek(0, SeekOrigin.Begin);
using (var sr = new StreamReader(ms))
{
requestBody = sr.ReadToEnd();
}
}
catch (Exception ex)
{
var test = ex;
}
}
}
catch (Exception ex)
{
var test = ex;
}
}
}
I am getting error of cannot access disposed object in content.CopyToAsync() method for POST and PATCH call and if i do same call from postman making it get i am not getting this error. I know there is no use of body in get call but just i was checking.