Before you start
Nefo offers residential proxies across 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).
By default the JDK disables Basic proxy authentication over HTTPS tunnels. Clear jdk.http.auth.tunneling.disabledSchemes so credentials are sent to the proxy.
- JDK 17+ with java.net.http available
- System property jdk.http.auth.tunneling.disabledSchemes set to empty
- A Nefo account with prepaid bandwidth
- A username/password from /dashboard/generator
- Your target country token
Java HttpClient proxy and Authenticator example
Build a client with proxy and authenticator:
Then send a request to https://api.ipify.org and read the body. Start the JVM with -Djdk.http.auth.tunneling.disabledSchemes="" so proxy Basic auth works over HTTPS. Change the country token to target any of 227 countries.
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.ProxySelector;
import java.net.http.HttpClient;
public class ProxyClient {
public static void main(String[] args) {
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress("gw.nefo.net", 9000)))
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("USERNAME-country-us", "PASSWORD".toCharArray());
}
})
.build();
}
}Java rotating vs sticky proxy sessions
Rotating sessions rotate the exit IP each request on HTTP port 9000, well suited to distributing many requests across residential exits.
Sticky sessions hold one IP from 1 minute up to 24 hours on HTTP port 10000. Use a token like USERNAME-country-us-session-svc4-lifetime-45 in the Authenticator username to keep one IP for a 45-minute session.
Geo-targeting in the Java proxy username
Targeting is expressed in the username token: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username string changes between regions.
Use the network lawfully, respect the target site's terms of service, and stay within applicable law and reasonable request rates.
Frequently asked questions
The JDK disables Basic authentication on HTTPS proxy tunnels by default, so the proxy replies 407. Launch the JVM with -Djdk.http.auth.tunneling.disabledSchemes="" (an empty value) so the username token and password are sent.
Use port 10000 and put a session token in the Authenticator username, for example USERNAME-country-us-session-abc-lifetime-45. Reuse one HttpClient so calls share the IP for up to 24 hours.
Yes. Configure a SOCKS proxy on port 11000 (rotating) or 12000 (sticky). Many HTTP clients and libraries accept SOCKS5 with username and password auth. Read more about SOCKS5 proxies.
Set the country token in the username, such as USERNAME-country-nl. Only the username string changes between regions, so the client code stays the same.
No. Generating credentials is free. Only traffic routed through the proxy consumes your prepaid bandwidth.