I am using ASP.NET Web API.
I want to download a PDF with C# from the API (that the API generates).
Can I just have the API return a byte[]? and for the C# application can I just do:
byte[] pdf = client.DownloadData("urlToAPI");?
and
File.WriteAllBytes()?
Better to return HttpResponseMessage with StreamContent inside of it.
Here is example:
UPDATE from comment by patridge:
Should anyone else get here looking to send out a response from a byte array instead of an actual file, you’re going to want to use
new ByteArrayContent(someData)instead ofStreamContent(see here).