Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android内置浏览器和下载_Android_Http_Apk_Android Browser - Fatal编程技术网

Android内置浏览器和下载

Android内置浏览器和下载,android,http,apk,android-browser,Android,Http,Apk,Android Browser,这让我快发疯了。我想提供一个.apk文件供下载。我测试过的所有浏览器都会毫无问题地下载我的文件。除了android的内置浏览器。出于某种奇怪的原因,它将重复对资源的请求。使用Burpusuite,我发现apk文件的传输是完美的。我代理文件,但我立即发送标题,使用curl我可以确认标题已发送,并且内容开始在下面的代码中传输。我已经将我的头与threema.ch发送的头进行了比较,threema.ch工作得非常完美 这些标题由我的应用程序发送: HTTP/1.1 200 OK Date: Sat,

这让我快发疯了。我想提供一个.apk文件供下载。我测试过的所有浏览器都会毫无问题地下载我的文件。除了android的内置浏览器。出于某种奇怪的原因,它将重复对资源的请求。使用Burpusuite,我发现apk文件的传输是完美的。我代理文件,但我立即发送标题,使用curl我可以确认标题已发送,并且内容开始在下面的代码中传输。我已经将我的头与threema.ch发送的头进行了比较,threema.ch工作得非常完美

这些标题由我的应用程序发送:

HTTP/1.1 200 OK
Date: Sat, 16 Aug 2014 16:41:01 GMT
Server: Apache/2.4.7
Content-Disposition: attachment; filename="test.apk"
Content-Type: application/vnd.android.package-archive
Transfer-Encoding: Chunked
这些头文件由Threema发送:

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 16 Aug 2014 17:49:10 GMT
Content-Type: application/vnd.android.package-archive
Content-Length: 14146751
Connection: keep-alive
Content-Disposition: attachment; filename="Threema-1.63.apk"
Strict-Transport-Security: max-age=31536000; includeSubdomains
我首先通过iframe加载了文件。目前,我正在使用HTTP重定向将浏览器重定向到下载。我提供了来自不同子域的文件。但是我也试着从同一个域传递文件,并使用html链接

这些是客户端发送的头。第一:

GET /download/download/NlnMhaeXmcjSosfqRTcG8YdxQgQGSxTWQeE10-GrH4U HTTP/1.1
Host: l.dl.test
Proxy-Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Linux; Android 4.4.4; Nexus 7 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Safari/537.36
Referer: http://l.google/device/deviceid/351cd7c24f637eb5?token=6Xf3nJIIMIa4toKrpTqgDGFjAKzeBBoaeduMmcIMeGY
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,en-US;q=0.8
X-Requested-With: com.android.browser
大约20秒后:

GET /download/download/NlnMhaeXmcjSosfqRTcG8YdxQgQGSxTWQeE10-GrH4U HTTP/1.1
User-Agent: Mozilla/5.0 (Linux; Android 4.4.4; Nexus 7 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Safari/537.36
Referer: 
cookie: 
Accept-Encoding: identity
Host: l.dl.test
Connection: Keep-Alive
我正在生成一个一次性使用的下载id。第二个请求将失败,因为id在第一个请求之后变得无效。如果我允许第二次尝试下载该文件,则下载有效

可能是android浏览器在第一次尝试时需要压缩内容,如果它获得标识内容,它将使用Accept Encoding identity进行第二次尝试?我还尝试设置内容编码:没有运气的身份

解决方法: 我在不发送.apk两次的情况下使其工作的唯一方法是使用这个非常愚蠢且容易出错的解决方法:

header("Content-Disposition: attachment; filename=\"test.apk\"");
header('Content-Type: application/vnd.android.package-archive');

// Ugly workaround for bug in built-in android browser.
if (
  isset($_SERVER['HTTP_X_REQUESTED_WITH'])
  && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'com.android.browser')
  && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
  && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'identity') === FALSE)
) {
    // The built-in android browser will make two requests for the apk
    // file, one with Accept-Encoding gzip and deflate and one with
    // Accept-Encoding identity. But it will only serve the second request
    // with Accept encoding identity. So stop the first request.

    // If the first request is shown, the workaround didn't work.
    die ("Oh no! I'm sorry. The built-in android browser has a nasty bug."
    . " It's hard to work around. If you see this the workaround failed."
    . " Please try downloading with a different browser.");
}

内容处置:附件一直是Android的问题。删除内容处置:附件没有帮助。但是谢谢。我不是故意让你把它拿走的。我的意思是让你在Internet上搜索该标题的帮助,或者切换到另一种文件下载方法。顺便说一下,如果我设置了Content Disposition:inline,它会工作,但会根据浏览器的请求打开。如果删除内容配置和内容类型,则相同。我尝试了很多不同的内容配置和内容类型组合,在所有浏览器中,要么显示文件,要么发送两个请求。