This article provides an example of using a proxy to make an HTTP request with the Java programming language.

Java Code

In this example, we use the Residential proxy below:

This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then add it, with authentication, to our proxy dictionary.

public class Application {
    private static String proxy_string = "";
    private static String[] proxy_parts = proxy_string.split(":");
    private static String ip_address = proxy_parts[0];
    private static int port = Integer.parseInt(proxy_parts[1]);
    private static String USERNAME = proxy_parts[2];
    private static String PASSWORD = proxy_parts[3];
    private static String URL_TO_GET = "";
    public static void main(String[] args) throws IOException {
        final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ip_address, port));
                new Authenticator() {
                    public PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(
                                USERNAME, PASSWORD.toCharArray());
        final URL url = new URL(URL_TO_GET);
        final URLConnection urlConnection = url.openConnection(proxy);
        final BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(urlConnection.getInputStream()));
        final StringBuilder response = new StringBuilder();
        String inputLine;
        while ((inputLine = bufferedReader.readLine()) != null) {
        System.out.println(String.format("Response:\n%s", response.toString()));

Last updated