jeasonlzy / okhttp-OkGo

OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Apache License 2.0
10.6k stars 2.55k forks source link

此链接下载问题大大的 http://marketdown1.gamedog.cn/among/game/celue/10413/wodeshijie015_an.apk #58

Closed loulousky closed 7 years ago

loulousky commented 8 years ago

此链接下载10次只有一次成功

                    OkHttpUtils.get(wlink)//
                            .tag(this)//

                            .execute(new FileCallback(Environment.getExternalStorageDirectory() + "/MinecraftContact", "minecraftpe.apk") {
                                @Override
                                public void onSuccess(File file, Call call, Response response) {
                                    processing_dialog.dismiss();
                                    Toast.makeText(getApplicationContext(),"下载完成",1).show();
                                    Intent intent = new Intent();
                                    intent.setAction(Intent.ACTION_VIEW);
                                    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");

                                    startActivity(intent);

                                }

                                @Override
                                public void downloadProgress(long currentSize, long totalSize, float progress, long networkSpeed) {
                                    super.downloadProgress(currentSize, totalSize, progress, networkSpeed);

                                    String downloadLength = Formatter.formatFileSize(getApplicationContext(), currentSize);
                                    String totalLength = Formatter.formatFileSize(getApplicationContext(), totalSize);

// String netSpeed = Formatter.formatFileSize(getApplicationContext(), networkSpeed); // tvNetSpeed.setText(netSpeed + "/S");

                                    processing_dialog.setMax(100);
                                    processing_dialog.setProgress((int) (progress * 100));

                                }

                                @Override
                                public void onError(Call call, Response response, Exception e) {
                                    super.onError(call, response, e);
                                    Toast.makeText(getApplicationContext(),e.toString(),1).show();
                                }
                            });

调用下面方法 进入下载队列后 image 显示304chongdingx 但是重定向后下载会提示 image然后什么回调都没有,忘作者能尽快看看哪里的BUG,这框架我都想换了

jeasonlzy commented 8 years ago

2016-09-09 19 25 35 2016-09-09 19 25 50 你看看我测试的代码。。是正常的。。每次都能成功。。也是拷贝你的代码测试的。。

jeasonlzy commented 8 years ago
qq20160909-0 2x

我知道你的问题了。。主要原因在于这个地址对304缓存做了兼容,第一次下载成功后,第二次再次下载的时候,对带上上次的缓存头,服务端认为本地缓存此次有效,所以打回了304响应。。

这时候客户端之所以没反应是因为304回调并不会走onSuccess,而是走的 onCacheSuccess。

解决办法有两个 第一:全局指定或者本次请求指定 CacheMode.No_CACHE 无缓存模式,每次都会下载并回调onSuccess 第二:重写回调onCacheSuccess,做相关处理操作。。

建议使用第一种方式。。

jeasonlzy commented 8 years ago

2016-09-09 20 11 39 这里是示例的正确代码