I have this C# code in my Azure function:
var data = new StringContent(requestBody, Encoding.UTF8, "application/json");
var request = await GetSubmissions.PostAsync("url", data);
if (request.IsSuccessStatusCode)
{
content = await request.Content.ReadAsStringAsync();
var response = req.CreateResponse(request.StatusCode);
await response.WriteStringAsync(content);
return response;
}
This receives data from an API call, and then returns it as response from that Azure function. All is good and I can see it being returned in Postman just fine, but I need to change the content type to JSON within the response as it is coming in as text.
As shown in this screenshot:

What can I try next?
Try explicitly setting the response header:
response.Headers.Add("Content-Type", "application/json; charset=utf-8");
Another option (though less preferable one) would be to deserialize the response and then serialize it back with WriteAsJsonAsync.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With