修复添加header,key大小写不分的问题

pull/330/head
laoyuyu 7 years ago
parent 60f575c803
commit efccdcb0c2
  1. 26
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  2. 4
      app/src/main/AndroidManifest.xml
  3. 4
      app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java

@ -104,14 +104,24 @@ class ConnectionHelp {
conn.setRequestProperty(key, entity.getHeaders().get(key)); 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"); conn.setRequestProperty("Charset", "UTF-8");
} }
if (keys == null || !keys.contains("User-Agent")) { if (conn.getRequestProperty("User-Agent") == null) {
conn.setRequestProperty("User-Agent", 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"); "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(); StringBuilder accept = new StringBuilder();
accept.append("image/gif, ") accept.append("image/gif, ")
.append("image/jpeg, ") .append("image/jpeg, ")
@ -133,15 +143,7 @@ class ConnectionHelp {
.append("*/*"); .append("*/*");
conn.setRequestProperty("Accept", accept.toString()); 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获取重定向地址 //302获取重定向地址
conn.setInstanceFollowRedirects(false); conn.setInstanceFollowRedirects(false);
return conn; return conn;

@ -16,10 +16,10 @@
<!--android:name=".test.TestActivity"--> <!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"--> <!--android:name=".test.AnyRunActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"--> <!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.TestGroupActivity"--> <!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"-->
<activity <activity
android:name=".MainActivity" android:name=".test.AnyRunActivity"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

@ -73,8 +73,10 @@ public class AnyRunnModule {
Aria.download(this) Aria.download(this)
.load(url) .load(url)
//.addHeader("Accept-Encoding", "gzip") //.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) .setRequestMode(RequestEnum.GET)
.setUrlProxy(Proxy.NO_PROXY) //.setUrlProxy(Proxy.NO_PROXY)
.setFilePath(path) .setFilePath(path)
//.resetState() //.resetState()
.start(); .start();

Loading…
Cancel
Save