0

That is really happening. I made test in PHP to confirm this.

I created a test.php file and put:

<?php
    error_log('Downloading...');
    header('Content-type: application/force-download');
    header('Content-Disposition: attachment; filename="test.txt"');
    echo 'test android download';
?>

So, when I open www.myurl/test.php via any Android mobile browser, in the error_log.log I get "Downloading..." two times.

When i open same URL in any other Mobile OS(Windows, IOS, etc.) I get only one time "Downloading..." in error_log.log file.

Does anyone know what's going on and how to avoid this ??

This is a big problem for me, because I perform user charging when somebody download a file. And now from Android Phones there are 2 charges for 1 downloaded file.

tasmaniski
  • 4,767
  • 3
  • 33
  • 65
  • "Does anyone know what's going on and how to avoid this ?" -- if I had to guess, Android issues an HTTP HEAD request, followed by the HTTP GET/POST/whatever request. – CommonsWare Jan 10 '13 at 13:32
  • 1
    .. so if the user refresh it's browser with this url he will be charged twice ??? (be careful with this kind of solution) – ben75 Jan 10 '13 at 13:32
  • @CommonsWare I'm not sure I understand you? Downloading the file is successfully. – tasmaniski Jan 10 '13 at 13:49
  • "Downloading the file is successfully" -- that surprises me, as `Content-Disposition: attachment` never used to work, but if it is now, that's a welcome improvement. You should certainly test on Android 2.x to see if your approach works at all. "I'm not sure I understand you?" -- if you do not know what an HTTP HEAD request is, you are well beyond my ability to help. – CommonsWare Jan 10 '13 at 13:57
  • That header has always worked, http://php.net/manual/en/function.header.php#example-4302 - first example from manual... although I know what the HTTP HEAD request is, your comment are well beyond ability to help, thanks anyway. – tasmaniski Jan 10 '13 at 14:37

2 Answers2

1

I am in a dead end :(

http://code.google.com/p/android/issues/detail?id=1978

The browser needs to hit the server to determine that something is a download, and than the download manager has to separately contact the server for downloading.

So, Android fire up first request to open dialogue box for "are you sure? - yes/no". And if user click "Yes" Android Forward request to Android DownloadManager and manager send second request to download file. (some Android version send request to DownloadManager immediately)

The problem is that both request, first and second, are type of GET (not HEAD).

tasmaniski
  • 4,767
  • 3
  • 33
  • 65
  • I've met the same issue. but on the first request I've got org.apache.catalina.connector.ClientAbortException with description java.net.SocketException: Connection reset by peer: socket – Diyko Mar 20 '13 at 10:17
0

In my case I receive two requests. First one throws org.apache.catalina.connector.ClientAbortException with description java.net.SocketException: Connection reset by peer: socket

So I just catch that exception and write log. I guess you can do the same and charge customers only after successful downloading

Diyko
  • 388
  • 1
  • 8
  • 28