Java
HttpClient (Java 11+)
import java.net.*;import java.net.http.*;
public class ProxyExample { public static void main(String[] args) throws Exception { var proxy = ProxySelector.of( new InetSocketAddress("connect.trueproxies.com", 8080) );
Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "your_username", "your_password".toCharArray() ); } });
var client = HttpClient.newBuilder() .proxy(proxy) .authenticator(Authenticator.getDefault()) .build();
var request = HttpRequest.newBuilder() .uri(URI.create("https://httpbin.org/ip")) .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); }}HttpURLConnection
import java.io.*;import java.net.*;
public class ProxyExample { public static void main(String[] args) throws Exception { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("connect.trueproxies.com", 8080));
Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "your_username", "your_password".toCharArray() ); } });
URL url = new URL("https://httpbin.org/ip"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream()) ); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } reader.close(); }}Country Targeting
return new PasswordAuthentication( "your_username-country-us", "your_password".toCharArray());