How to read application/pdf content type from HttpResponseMessage and convert it into stream

I have a Web API which connects to another end point. A GET method from the second Web API returns an application/pdf content-type. here I am successfully getting the data. How I can convert the response.Content to file/memory stream and return the value?

 public async Task functionname(ApplicationApiRoutes.APIRoutes route, string token = "", int TimeoutMinutes = 5, CancellationToken cancellationToken = default, params string[] routeparams) < T Response = default; try < ApplicationApiRoutes._RouteHashTable.TryGetValue(route, out string FormattedRoute); FormattedRoute = String.Format(FormattedRoute, routeparams); using (var request = new HttpRequestMessage(HttpMethod.Get, $"")) < if (!String.IsNullOrWhiteSpace(token)) < request.Headers.Add("Cookie", $"access_token="+ token); >using (var response = await _httpclient .SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)) < response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); Response = JsonConvert.DeserializeObject(result, _jsonsettings); > > > catch (Exception ex) < >return Response; > 
asked May 17, 2021 at 14:36 5 1 1 silver badge 5 5 bronze badges

Ah, so you have a generic function that converts json to some type T. You can't treat a pdf as json. IMHO write a new method that just returns the body stream and use that instead.