There are a number of similar questions regarding extracting the content of an HttpResponseMessage, but most are looking for JSON or text.
I have an API in c# that calls another API which returns a Razor page. When I call the second API from Postman, it returns nicely formatted HTML that could be displayed in a browser right away. All I want my API to do (in this instance) is act as a middleman between the browser and the second API.
var client = new HttpClient();
const string uri = "Second API";
var formData = new Dictionary<string, string>
{
// Data being sent to second API.
{"path", "/somehwere/somefile.extension"}
};
var encodedFormData = new FormUrlEncodedContent(formData);
var response = await client.PostAsync(uri, encodedFormData);
Now I have the response. If I do the following:
var test = await response.Content.ReadAsStringAsync();
The result is a string with various formatting characters such as "/n". This is not valid HTML and cannot be set as the src of an IFrame in the client browser (which is ultimately what I want to do).
I don't have an issue returning the data that I have extracted to the initial caller, my issue is with formatting.
How do I return valid HTML when I know that the second API is returning it (because Postman displays the html nicely, and because the browser can make the request and display it properly)?
Content-Typeheader of the response?