Download served from WebApi fails on Android device, works on Asp.Net MVC -


since newer version of android webview (currently running on v48), pdf downloads form application stopped work. downloading desktop browsers, wp10 , ios function properly.

the behavior:
says, download has started... few minutes later notification " download unsuccessful".

the download comes webapi controller, hosted on azure. tried tons of different suggested https headers , combination of headers. compared headers coming other websites, download works on device. no success.
got curious , impemlented download in asp.net mvc (5) controller (same project) , modified headers in webapi (2.2) counterpart. => download worked!. compared both responses in fiddler, except url - same.

any idea else difference?

here code bits:

mvc test (working)

public fileresult cooldocument() {     // hardcoded binary data (minimum valid pdf)     byte[] bytearr = new byte[] { 37, 80, ... };       // making headers same in webapi response     response.addheader("content-disposition", "attachment; filename=\"test.pdf\"");     response.headers.add("expires", "-1");     response.headers.add("cache-control", "no-cache");     response.headers.add("x-application-version", "1.0.5919.31987");     response.headers.add("x-environment", "acceptance");     response.headers.add("pragma", "no-cache");                 return file(bytearr, "application/pdf"); } 

webapi test (not working) headers come form filter, tried without them too

[httpget] public httpresponsemessage cooldocument() {     httpresponsemessage response = new httpresponsemessage(httpstatuscode.ok);      /// hardcoded binary data (minimum valid pdf)     byte[] bytearr = new byte[] { 37, 80, ... };      response.content = new bytearraycontent(bytearr);      response.content.headers.contenttype =         new mediatypeheadervalue("application/pdf");      response.content.headers.contentdisposition =         new contentdispositionheadervalue("attachment") { filename = "\"test.pdf\"", };     return response; } 

here how headers in fiddler:

http/1.1 200 ok cache-control: no-cache pragma: no-cache content-length: 2729 content-type: application/pdf expires: -1 server: microsoft-iis/8.0 x-environment: acceptance x-application-version: 1.0.5919.31987 content-disposition: attachment; filename="test.pdf" x-aspnet-version: 4.0.30319 x-powered-by: asp.net date: wed, 16 mar 2016 16:50:41 gmt 

finally figured out went wrong.

android (and windows phone 8.1 too) makes 2 requests when starting download. assume, first 1 coming browser (chrome) , second 1 android download manager.
second request had different request headers original request. noticed second request after started debug server code remotely, because request download manager has logically not been recorded in chrome developer tools.
anyway, second request caused "languge-filter" throw exception, because of dumb null pointer exception occurred reading out accept-language header - not present in second request.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -