package example;
import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;
public class Example {
public static void main(String[] args) throws Exception {
HttpHost proxy = new HttpHost("brd.superproxy.io", 44445);
String res = Executor.newInstance()
.auth(proxy, "brd-customer-<customer_id>-zone-<zone_name>", "<zone_password>")
.execute(Request.Get("http://brdtest.com/myip.json").viaProxy(proxy))
.returnContent().asString();
System.out.println(res);
}
}
/*In the above example, we are not explicitly ignoring SSL
I will share with you a short code I wrote that does ignore SSL using JAVA (was taken from cloud proxy manager examples) */
import java.io.*;
import java.net.*;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
import java.util.Base64;
public class Example {
public static void main(String[] args) throws Exception {
// Disable restricted headers for proxy authentication
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
// Set up a TrustManager that does not validate certificate chains
SSLContext sc = SSLContext.getInstance("SSL");
TrustManager trust_manager = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
};
TrustManager[] trust_all = new TrustManager[] { trust_manager };
sc.init(null, trust_all, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Set up the proxy and open a connection
URL url = new URL("https://geo.brdtest.com/mygeo.json");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("brd.superproxy.io", 44445));
URLConnection yc = url.openConnection(proxy);
// Set default Authenticator for proxy authentication
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("brd-customer-<customer_id>-zone-<zone_name>", "<zone_password>".toCharArray());
}
});
// Read and print the response from the server
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}