HTTPDownloader: Fix user agent sending on Windows/Android
This commit is contained in:
1 parent
251043f11a
commit
d41b5be908
10 files changed
+40
-33
No files matched your search
@@ -15,17 +15,21 @@ import java.net.URL;
|
||||
public class URLDownloader {
|
||||
private int statusCode = -1;
|
||||
private byte[] data = null;
|
||||
private final String userAgent;
|
||||
|
||||
public URLDownloader() {
|
||||
public URLDownloader(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
static private HttpURLConnection getConnection(String url) {
|
||||
private HttpURLConnection getConnection(String url) {
|
||||
try {
|
||||
final URL parsedUrl = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) parsedUrl.openConnection();
|
||||
if (connection == null)
|
||||
throw new RuntimeException(String.format("openConnection(%s) returned null", url));
|
||||
|
||||
if (userAgent != null)
|
||||
connection.addRequestProperty("User-Agent", userAgent);
|
||||
return connection;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in new issue
Block a user