I am currently in my .NET (c#) backend, making a GET call to an external URL which returns a responseType: 'stream'
. In this case it is streaming back data which should be a valid .PDF file once complete. Calling this external API from Postman works fine and displays the pdf, but my code doesnt seem to be getting all of the streamed data, causing an invalid file.
Here is my function:
private async Task<string?> ReadFileData(string url)
{
string fileData = null;
using (var response = await _httpClient.GetAsync(url))
{
response.EnsureSuccessStatusCode();
var stream = await response.Content.ReadAsStreamAsync();
fileData += await response.Content.ReadAsStringAsync();
}
return fileData;
}
Just one of the things I’ve tried, but I dont seem to be streaming the entire dataset, although I am getting the first 15 or so lines of what should be a multiple hundreds of lines (of raw text) pdf file, I did quite a bit of research but didn’t seem to find anything. I’m sure I’m missing something dumb regarding the data streaming, if anyone has any incite that’d be great