Proxy exits in 64 countries and 172 cities, sold per GB, IP, day or request.

Code and command line

Java proxy setup

Java has a built-in HTTP client since version 11 with proper proxy support, but one default catches almost everyone. The JDK refuses to send Basic credentials when it opens an HTTPS tunnel through a proxy. Requests to https pages then fail with a 407 even though the login is correct.

The fix is a single system property. This guide shows where to put it, how to wire the proxy and the Authenticator, and an OkHttp version that does not depend on that property at all.

What do you need before adding a proxy in Java?

Tick these off before the first step. Your login and password appear in your account once the first top-up of $40 or more has been credited.

Requirements for Java
RequirementDetail
JDK 11 or newerFor java.net.http.HttpClient. Any current LTS release works.
The tunnelling propertyjdk.http.auth.tunneling.disabledSchemes set to an empty value.
TopProxy login and passwordLogin such as tp7k2m9_country-us.
OkHttp, optionalcom.squareup.okhttp3:okhttp for the OkHttp step.

Where do the proxy host, port and login go in Java?

Work through the steps in order. Swap YOUR_PASSWORD for your proxy password and tp7k2m9 for your account name.

  1. Allow Basic auth for HTTPS tunnels

    The JDK lists Basic in jdk.http.auth.tunneling.disabledSchemes by default, which blocks the login on CONNECT. Clear the list. A JVM flag is the most reliable place because it is read before any networking class loads.

    java -Djdk.http.auth.tunneling.disabledSchemes= -jar app.jar

    Tip.If you set it in code, do it before creating any HttpClient or opening a URL connection, otherwise the old value may already be cached.

  2. Create an HttpClient with proxy and Authenticator

    The ProxySelector points every request at the gateway. The Authenticator returns the login only when the request comes from the proxy, so it never leaks to a website that asks for credentials.

    import java.net.*;
    import java.net.http.*;
    
    public class ProxyCheck {
        public static void main(String[] args) throws Exception {
            System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
            String login = "tp7k2m9_country-us";
            String password = System.getenv("TOPPROXY_PASSWORD");
    
            HttpClient client = HttpClient.newBuilder()
                .proxy(ProxySelector.of(new InetSocketAddress("proxy.topproxy.shop", 8080)))
                .authenticator(new Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        if (getRequestorType() == RequestorType.PROXY) {
                            return new PasswordAuthentication(login, password.toCharArray());
                        }
                        return null;
                    }
                })
                .build();
    
            HttpRequest req = HttpRequest.newBuilder(URI.create("https://ipinfo.io/json")).build();
            HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString());
            System.out.println(res.statusCode() + " " + res.body());
        }
    }
  3. Or use OkHttp with a proxy authenticator

    OkHttp answers the proxy challenge itself through proxyAuthenticator, so the JDK property does not apply. It is a good choice on Android and in projects that already use OkHttp.

    OkHttpClient client = new OkHttpClient.Builder()
        .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.topproxy.shop", 8080)))
        .proxyAuthenticator((route, response) -> {
            String cred = Credentials.basic("tp7k2m9_country-us", System.getenv("TOPPROXY_PASSWORD"));
            return response.request().newBuilder().header("Proxy-Authorization", cred).build();
        })
        .build();
    
    try (Response r = client.newCall(new Request.Builder().url("https://ipinfo.io/json").build()).execute()) {
        System.out.println(r.body().string());
    }

How can you confirm the proxy is active in Java?

Run ProxyCheck. A 200 with a JSON body that shows a foreign address means the tunnel and the login both work. A 407 almost always means the tunnelling property was not applied.

export TOPPROXY_PASSWORD="your-password"
java -Djdk.http.auth.tunneling.disabledSchemes= ProxyCheck.java

The response shown here is shortened to the fields that matter. The region and time zone follow the exit, in this case India.

GET https://ipinfo.io/json
{
  "ip": "198.51.100.47",
  "city": "Bengaluru",
  "region": "Karnataka",
  "country": "IN",
  "timezone": "Asia/Kolkata"
}

198.51.100.47 is an address reserved for documentation. A live check prints a real exit.

How do you switch between rotating and held IPs in Java?

HttpClient pools connections, so requests can share an exit while a pooled connection lives. Build a new client when you need a new address on a rotating login. For a fixed address through a whole job, use a session login.

String login = "tp7k2m9_country-us";

How the login is put together

Every setting lives in the login, joined with underscores. Nothing else in Java changes when you switch location or session.

Parts of a TopProxy login
PartMeaningRule
tp7k2m9Your account nameAlways first. Yours is shown in your account and replaces tp7k2m9 in every example here.
_country-usExit countryTwo-letter code in lowercase. 64 countries to choose from.
_city-new-yorkExit city, optionalLowercase, spaces become hyphens. 172 cities in total.
_session-a1b2c3Session name, optionalLetters and digits you pick. Same name, same exit. New name, new exit.
_life-30Session life in minutesOnly with a session. Residential 1 to 120 minutes, mobile 1 to 60 minutes, long session ISP up to 12 hours (life 720).

All parts togethertp7k2m9_country-us_city-new-york_session-a1b2c3_life-30

How do you choose an exit country or city in Java?

Put the country and city into the login string. One client per login keeps the setup simple.

String login = "tp7k2m9_country-in";

Codes and city values for all 64 countries are listed on the proxy locations pages.

How do you fix a 407 or connection error in Java?

Find the line that matches what you see. Most problems come down to the login, the port or the network you are on.

Java symptoms, causes and fixes
SymptomLikely causeFix
407 on every https URL, http URLs fineBasic is still disabled for tunnels.Pass -Djdk.http.auth.tunneling.disabledSchemes= on the command line.
IOException: too many authentication attemptsThe Authenticator keeps returning a refused login.Check the login and password, and that the environment variable is visible to the JVM.
NullPointerException in the AuthenticatorTOPPROXY_PASSWORD is not set, so getenv returned null.Set the variable or read the password from your config system.
SOCKS proxy ignored by HttpClientjava.net.http does not support SOCKS proxies.Use the HTTP port 8080, or HttpURLConnection with a SOCKS Proxy object.

Still stuck? Run the same login through the cURL check. If cURL connects, the issue is in the Java settings. If it does not, write to support with the error text.

What kind of proxy pairs well with Java?

All products sit behind the same gateway and share one prepaid balance, so moving from one to another means buying the other product and changing the login, nothing more.

Calling pages from code at scale? The TopProxy API docs cover the Scraping API, which renders pages and retries on its own.

What else do Java users ask about proxies?

Why does Java disable Basic auth for tunnels?

It is a conservative default added years ago, because Basic credentials are only encoded, not encrypted, on the hop to the proxy. Clearing the property restores the usual behaviour that other HTTP clients have.

Can I use the http.proxyHost system properties instead?

Yes for HttpURLConnection: set https.proxyHost and https.proxyPort, plus a default Authenticator. HttpClient ignores those properties unless you pass ProxySelector.getDefault().

Does this work with Spring WebClient or RestTemplate?

Both sit on top of an HTTP library such as Reactor Netty, Apache HttpClient or the JDK client. Configure the proxy on that underlying client with the same host, port and login.

How do I use the SOCKS5 port from Java?

With HttpURLConnection and a Proxy of type SOCKS pointed at port 1080, plus a default Authenticator for the login. HttpClient itself does not speak SOCKS, so the HTTP port is the simpler route.

Is the login cached between requests?

Yes. Once the Authenticator has answered, HttpClient reuses the credentials for later requests to the same proxy, so the callback is not called every time.

Ready to connect Java?

Open an account, add $40 or more in crypto, and your login and password are waiting in the account area.