问题
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.
回答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).
回答2:
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
来源:https://stackoverflow.com/questions/14259037/android-is-sending-2-requests-to-download-one-file-via-mobile-browser