Android发送2个请求,通过移动浏览器下载一个文件 [英] Android is sending 2 requests to download one file via mobile browser

查看:142
本文介绍了Android发送2个请求,通过移动浏览器下载一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是真的发生。我在PHP中进行了测试以确认这一点。

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

我创建了一个test.php文件,并将:

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';
?>

所以,当我通过任何Android手机浏览器打开www.myurl / test.php时,在error_log .log我得到下载...两次。

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

当我在任何其他移动操作系统(Windows,IOS等)中打开同一个URL时,我只得到一个时间下载...在error_log.log文件中。

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 ??

这对我来说是一个大问题,因为当有人下载​​文件时,我执行用户计费。现在来自Android手机,1个下载的文件有2个费用。

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.

推荐答案

我处于死胡同:(

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.

所以,Android首先要求打开对话框你确定吗?
如果用户点击是Android转发请求到Android DownloadManager和管理员发送第二个请求下载文件(一些Android版本立即向DownloadManager发送请求)

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)

问题是,第一和第二个请求都是GET(不是HEAD)的类型。

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

这篇关于Android发送2个请求,通过移动浏览器下载一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆