|
|
|
@ -63,38 +63,50 @@ class ConnectionHelp { |
|
|
|
|
static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn) |
|
|
|
|
throws ProtocolException { |
|
|
|
|
conn.setRequestMethod(entity.requestEnum.name); |
|
|
|
|
Set<String> keys = null; |
|
|
|
|
if (entity.headers != null && entity.headers.size() > 0) { |
|
|
|
|
Set<String> keys = entity.headers.keySet(); |
|
|
|
|
keys = entity.headers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
conn.setRequestProperty(key, entity.headers.get(key)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
conn.setRequestProperty("Charset", "UTF-8"); |
|
|
|
|
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"); |
|
|
|
|
StringBuilder accept = new StringBuilder(); |
|
|
|
|
accept.append("image/gif, ") |
|
|
|
|
.append("image/jpeg, ") |
|
|
|
|
.append("image/pjpeg, ") |
|
|
|
|
.append("image/webp, ") |
|
|
|
|
.append("image/*, ") |
|
|
|
|
.append("application/xml") |
|
|
|
|
.append("application/xaml+xml, ") |
|
|
|
|
.append("application/xhtml+xml, ") |
|
|
|
|
.append("application/x-shockwave-flash, ") |
|
|
|
|
.append("application/x-ms-xbap, ") |
|
|
|
|
.append("application/x-ms-application, ") |
|
|
|
|
.append("application/msword, ") |
|
|
|
|
.append("application/vnd.ms-excel, ") |
|
|
|
|
.append("application/vnd.ms-xpsdocument, ") |
|
|
|
|
.append("application/vnd.ms-powerpoint, ") |
|
|
|
|
.append("text/plain, ") |
|
|
|
|
.append("text/html, ") |
|
|
|
|
.append("*/*"); |
|
|
|
|
conn.setRequestProperty("Accept", accept.toString()); |
|
|
|
|
conn.setRequestProperty("Accept-Encoding", "identity"); |
|
|
|
|
conn.setRequestProperty("Accept-Charset", "UTF-8"); |
|
|
|
|
conn.setRequestProperty("Connection", "Keep-Alive"); |
|
|
|
|
if (keys == null || !keys.contains("Charset")) { |
|
|
|
|
conn.setRequestProperty("Charset", "UTF-8"); |
|
|
|
|
} |
|
|
|
|
if (keys == null || !keys.contains("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"); |
|
|
|
|
} |
|
|
|
|
if (keys == null || !keys.contains("Accept")) { |
|
|
|
|
StringBuilder accept = new StringBuilder(); |
|
|
|
|
accept.append("image/gif, ") |
|
|
|
|
.append("image/jpeg, ") |
|
|
|
|
.append("image/pjpeg, ") |
|
|
|
|
.append("image/webp, ") |
|
|
|
|
.append("application/xml, ") |
|
|
|
|
.append("application/xaml+xml, ") |
|
|
|
|
.append("application/xhtml+xml, ") |
|
|
|
|
.append("application/x-shockwave-flash, ") |
|
|
|
|
.append("application/x-ms-xbap, ") |
|
|
|
|
.append("application/x-ms-application, ") |
|
|
|
|
.append("application/msword, ") |
|
|
|
|
.append("application/vnd.ms-excel, ") |
|
|
|
|
.append("application/vnd.ms-xpsdocument, ") |
|
|
|
|
.append("application/vnd.ms-powerpoint, ") |
|
|
|
|
.append("text/plain, ") |
|
|
|
|
.append("text/html, ") |
|
|
|
|
.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; |
|
|
|
|