From efccdcb0c23e76d05f3e8dbf8c352e70cf9b5569 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Wed, 27 Jun 2018 20:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0header,key?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99=E4=B8=8D=E5=88=86=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../download/downloader/ConnectionHelp.java | 26 ++++++++++--------- app/src/main/AndroidManifest.xml | 4 +-- .../arialyy/simple/test/AnyRunnModule.java | 4 ++- 3 files changed, 19 insertions(+), 15 deletions(-) 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();