Enable HttpDownloader to use URL-based HTTP Basic Authentication.
This commit is contained in:
parent
f7a0063495
commit
405e411200
@ -20,6 +20,7 @@ import java.net.SocketAddress;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
import org.apache.commons.net.util.Base64;
|
||||||
|
|
||||||
public class HttpDownloader extends Downloader {
|
public class HttpDownloader extends Downloader {
|
||||||
private static final String TAG = "HttpDownloader";
|
private static final String TAG = "HttpDownloader";
|
||||||
@ -87,6 +88,10 @@ public class HttpDownloader extends Downloader {
|
|||||||
connection = (HttpURLConnection) sourceUrl.openConnection(proxy);
|
connection = (HttpURLConnection) sourceUrl.openConnection(proxy);
|
||||||
} else {
|
} else {
|
||||||
connection = (HttpURLConnection) sourceUrl.openConnection();
|
connection = (HttpURLConnection) sourceUrl.openConnection();
|
||||||
|
final String userInfo = sourceUrl.getUserInfo();
|
||||||
|
if (userInfo != null) {
|
||||||
|
connection.setRequestProperty("Authorization", "Basic " + Base64.encodeBase64String(userInfo.getBytes()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,4 +148,4 @@ public class HttpDownloader extends Downloader {
|
|||||||
public void close() {
|
public void close() {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user