I have an API API that looks like this:
using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Web.Http; using System.Threading.Tasks; using System.IO; namespace APIIntegration.Controllers { public class TestController : ApiController {
In short, this controller is trying to load a 256-byte file into the browser. At first it works, but when the downloaded file is checked, the size is 512 bytes instead of the expected 256 bytes, and non-printable characters will be destroyed.
How can I change this code so that binary data can be loaded correctly?
Edit: It should also be mentioned that I saw a similar question here: Problems downloading the pdf file from the api web service , where the problem was fixed by adding a content length header, but this did not solve for me.
Edit: I modified the source code above to give a complete working example of how to reproduce.
Edit: I found that the above code really works correctly when I provide the address in the address bar, but when using Javascript to start the download, where I have a problem.
source share