diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java index b19393d0..a98b0054 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java @@ -104,14 +104,24 @@ class ConnectionHelp { conn.setRequestProperty(key, entity.getHeaders().get(key)); } } - if (keys == null || !keys.contains("Charset")) { + + if (conn.getRequestProperty("Accept-Encoding") == null) { + conn.setRequestProperty("Accept-Encoding", "identity"); + } + if (conn.getRequestProperty("Accept-Charset") == null) { + conn.setRequestProperty("Accept-Charset", "UTF-8"); + } + if (conn.getRequestProperty("Connection") == null) { + conn.setRequestProperty("Connection", "Keep-Alive"); + } + if (conn.getRequestProperty("Charset") == null) { conn.setRequestProperty("Charset", "UTF-8"); } - if (keys == null || !keys.contains("User-Agent")) { + if (conn.getRequestProperty("User-Agent") == null) { conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); } - if (keys == null || !keys.contains("Accept")) { + if (conn.getRequestProperty("Accept") == null) { StringBuilder accept = new StringBuilder(); accept.append("image/gif, ") .append("image/jpeg, ") @@ -133,15 +143,7 @@ class ConnectionHelp { .append("*/*"); conn.setRequestProperty("Accept", accept.toString()); } - if (keys == null || !keys.contains("Accept-Encoding")) { - conn.setRequestProperty("Accept-Encoding", "identity"); - } - if (keys == null || !keys.contains("Accept-Charset")) { - conn.setRequestProperty("Accept-Charset", "UTF-8"); - } - if (keys == null || !keys.contains("Connection")) { - conn.setRequestProperty("Connection", "Keep-Alive"); - } + //302获取重定向地址 conn.setInstanceFollowRedirects(false); return conn; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d3f0449e..42eeca06 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,10 +16,10 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java index b56727f8..0c34b9a0 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java @@ -73,8 +73,10 @@ public class AnyRunnModule { Aria.download(this) .load(url) //.addHeader("Accept-Encoding", "gzip") + .addHeader("headers", "Referer: http://www.bilibili.com/") + .addHeader("user-agent", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36") .setRequestMode(RequestEnum.GET) - .setUrlProxy(Proxy.NO_PROXY) + //.setUrlProxy(Proxy.NO_PROXY) .setFilePath(path) //.resetState() .start();