title: Android browser won't download pdf file
body: <p>I have a web app that lets users download a pdf file. It is ASP.NET MVC and it all works fine on desktop browsers, iPhone, Android Chrome, and in a native Android app that overrides the  Web View setDownloadListener().</p>
  
  <p>However, the download doesn't seem to work when using the default Android browser. I'm testing on a Galaxy Nexus running 4.2.2 and on a Nexus S 4g running 2.3.7. I have PDF viewer apps installed on both devices.</p>
  
  <p>When I test in Android Chrome, the user sees a "Starting Download..." toast and then a Download complete notification is shown in the status bar. The user can touch this notification to open the file in a pdf viewer. In Android's default browser there is no toast and no download file is saved.</p>
  
  <p>I put wireshark on the network and I see the following request:</p>
  
  <pre><code>GET /appapth/ViewPDF/8383600280757433_11_05_2012 HTTP/1.1
  Host: 192.168.1.117
  Connection: keep-alive
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  X-Requested-With: com.google.android.browser
  User-Agent: Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; Galaxy Nexus Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
  Accept-Encoding: gzip,deflate
  Accept-Language: en-US
  Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
  Cookie: (lots o'cookie data)
  </code></pre>
  
  <p>and the response is:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: no-cache, no-store, must-revalidate
  Pragma: no-cache
  Content-Type: application/pdf
  Content-Encoding: gzip
  Expires: -1
  Server: Microsoft-IIS/7.5
  Set-Cookie: ___TempData=; path=/
  Set-Cookie: ___TempData=(lot's o'cookie data); path=/; HttpOnly
  Date: Mon, 01 Apr 2013 18:22:20 GMT
  Content-Length: 48244
  
  ......YQ.....T...?J.h)...!E.S(lots o'binary data)
  </code></pre>
  
  <p>As you can see from the trace application/pdf content is downloaded. You can also see that I'm not using the content-disposition header and the response is downloaded with gzip encoding.</p>
  
  <p>Any ideas on why this does not work on the Default Android browser? The user does not have access to the downloaded data and no viewer (or intent) is launched. The response is just silently ignored. (I'm guessing that Android default browser requires the content-disposition or doesn't like Gzip on the download, but I'm just guessing)</p>
  
  <p>Update ----</p>
  
  <p>I removed our action filter that was implementing Gzip compression and I added in the 
  Content-Disposition attachment header. so, MVC code in my controller is like:</p>
  
  <pre><code>public virtual ActionResult ViewPDF(string id)
  {
      try
      {
          byte[] pdf = GetPDFContent(id);
          FileContentResult fcr = new FileContentResult(pdf, "application/pdf");
          fcr.FileDownloadName = id + ".pdf";            
          return fcr;
      }
  </code></pre>
  
  <p>and the Http response is now:</p>
  
  <pre><code>HTTP/1.1 200 OK 
  Cache-Control: no-cache, no-store, must-revalidate 
  Pragma: no-cache 
  Content-Type: application/pdf 
  Expires: -1 
  Server: Microsoft-IIS/7.5 
  Content-Disposition: attachment; filename=433_07_05_2012.pdf 
  Set-Cookie: ___TempData=; path=/ 
  Set-Cookie: ___TempData=(lots o'cookie data);path=/; HttpOnly 
  Date: Mon, 01 Apr 2013 19:56:07 GMT 
  Content-Length: 59069
  
  %PDF-1.3 %.... 13 0 obj &lt;&lt; (lots o'binary pdf data)
  </code></pre>
  
  <p>There is no longer any gzip and there is a content-disposition, but on the Android default browser there is still no visible download.</p>
  
  <p>Update 2 ---</p>
  
  <p>tried the suggestions from <a href="https://stackoverflow.com/a/5728859/90236">https://stackoverflow.com/a/5728859/90236</a> and <a href="http://winzter143.blogspot.com/2012/03/android-handling-of-content-disposition.html" rel="nofollow noreferrer">http://winzter143.blogspot.com/2012/03/android-handling-of-content-disposition.html</a> and <a href="http://androidforums.com/application-development/256987-android-phone-download-issue-asp-net-website.html" rel="nofollow noreferrer">http://androidforums.com/application-development/256987-android-phone-download-issue-asp-net-website.html</a> but I still get the same results.</p>