In Some cases I have NewtonSoft JSON.NET and in my controller I just return the Jobject from my controller and all is good.
But I have a case where I get some raw JS
This works for me in .NET Core 3.1.
private async Task ChannelCosmicRaysAsync(HttpRequestMessage request)
{
// client is HttpClient
using var response = await client.SendAsync(request).ConfigureAwait(false);
var responseContentString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Response.StatusCode = (int)response.StatusCode;
return Content(responseContentString, "application/json");
}
public Task X()
{
var request = new HttpRequestMessage(HttpMethod.Post, url);
(...)
return ChannelCosmicRaysAsync(request);
}
ContentResult is Microsoft.AspNetCore.Mvc.ContentResult.
Please note this doesn't channel headers, but in my case this is what I need.