I develop a react-native app, for android, I use the RNFetchBlob to download the APK. and in android, RNFetchBlob uses OkHttp library to download the file. But the APK can not download. when I put the link in android, it can download the file successfully.
I try to replace it us the other URL, RNFetchBlob can download the file.
But my URL is a simple url: http://host:port/AppDownLoad/publish/some.apk
the RNFetchBlob config is the below:
RNFetchBlob.config({
path: dirs.DCIMDir + "/Some.apk",
timeout:180000, //超时三分钟
})
.fetch("GET", APK_URL)
.progress({ count: 10 }, (received, total) => {
let currentProgress = received / total;
})
.then(res => {
if(res.respInfo.timeout){
Linking.openURL(APKURL)
return;
}
android.actionViewIntent(
res.path(),
"application/vnd.android.package-archive"
);
})
.catch(error => {
console.log(error);
// Linking.openURL(APKURL)
});
the third library OkHttp source code is:
OkHttpClient.Builder clientBuilder;
if (this.options.trusty) {
clientBuilder = RNFetchBlobUtils.getUnsafeOkHttpClient(client);
} else {
clientBuilder = client.newBuilder();
}
final Request.Builder builder = new Request.Builder();
try {
builder.url(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
}
builder.method("GET", null);
final Request req = builder.build();
clientBuilder.connectionPool(pool);
clientBuilder.retryOnConnectionFailure(false);
clientBuilder.followRedirects(options.followRedirect);
clientBuilder.followSslRedirects(options.followRedirect);
clientBuilder.retryOnConnectionFailure(true);
OkHttpClient client = enableTls12OnPreLollipop(clientBuilder).build();
Call call = client.newCall(req);
taskTable.put(taskId, call);
call.enqueue(new okhttp3.Callback(),{callback}
Could anyone tell me why?