How to enable your app connected to internet using proxy. Note: this only works http, still working on https.
private String fetchUsingProxy() throws IOException {
URL url = new URL("http://www.google.com");
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("aldo@yoursite.com", "password".toCharArray());
}
};
Authenticator.setDefault(authenticator);
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxy.yoursite.com", 8080));
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(proxy);
InputStream in = urlConnection.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[1024];
out.write(buffer, 0, bytesRead);
while((bytesRead = in.read(buffer)) > 0){
out.write(buffer, 0, bytesRead);
}
out.close();
out.flush();
return out.toString();
}
also webi android library support proxy