I have a Web API which successfully connects to another Web API using HttpClient. A GET method from the second Web API returns an application/pdf content-type.
I can see the content-type of the response at the debugger, using:
var response = await client.GetAsync("{url}")
The question is, how can I read that stream and successfully return it in my own get method?
Preferably, the method type should be IHttpActionResult.
You can forward the content on and also get all the necessary details from the response of the other request
public async Task<IHttpActionResult> MyAction() {
//...code removed for brevity
var response = await client.GetAsync("{url}");
if (response.IsSuccessStatusCode) {
var message = Request.CreateResponse(HttpStatusCode.OK);
message.Content = response.Content;
return ResponseMessage(message);
}
return BadRequest(); //or some other status response.
}
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