- Host
- gw.prokso.com
- Port
- 823 HTTP · 824 SOCKS5 - new IP per request · 10000–20000 sticky session, HTTP(S) and SOCKS5
- Username and password
- in your dashboard, on the plan page
Your dashboard generates ready-made lines in the format you need: choose the country, IP type and protocol.
- HttpClient: ProxySelector.of for the address, an Authenticator checking RequestorType.PROXY for the username
- For https through a password-protected proxy, launch the JVM with -Djdk.http.auth.tunneling.disabledSchemes=""
- SOCKS5 goes through a SOCKS-type java.net.Proxy on port 824
In Java you can connect a proxy through three APIs, and they behave differently: java.net.http.HttpClient (Java 11+), the older HttpURLConnection and JVM system properties. The main trap is not in the code but in the JDK settings: by default Java does not send the proxy username and password when it opens an https site through a tunnel. Below is how to get around this and where each API reaches its limits.
Step 1. Split the proxy string for ProxySelector
ProxySelector.of takes the host and port as an InetSocketAddress, and Java gets the username and password separately, from an Authenticator. So split the proxy string from the dashboard into two parts: gw.prokso.com with the port goes into the selector, and the username and password from the “Access” block go into the authenticator.
Choose the port for the task. 823 is HTTP, and every request gets a new IP. The 10000-20000 range gives a sticky IP for 1 to 120 minutes, with each port holding its own address. 824 is SOCKS5 with rotation, but in Java it needs a different API (step 5). The country is written in the username, so for another country only the username string changes.
Step 2. HttpClient with ProxySelector and Authenticator
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
public class ProxyCheck {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress("gw.prokso.com", 823)))
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() != RequestorType.PROXY) {
return null;
}
return new PasswordAuthentication("USERNAME", "PASSWORD".toCharArray());
}
})
.connectTimeout(Duration.ofSeconds(15))
.build();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.ipify.org"))
.timeout(Duration.ofSeconds(30))
.build();
System.out.println(client.send(request, HttpResponse.BodyHandlers.ofString()).body());
}
}The Authenticator checks getRequestorType(): RequestorType.PROXY means the password is requested by the proxy, not by the site. Without this check, your Prokso username would go to any site that responds with an authentication request.
According to the documentation, an HttpClient is immutable once built and is meant for many requests, and creating a new client for every operation usually prevents connections from being reused. So keep one client per proxy port.
Both timeouts matter here. Without HttpRequest.Builder.timeout a request waits for a response forever, while connectTimeout only limits establishing the connection and, if it expires, throws HttpConnectTimeoutException.
Step 3. Allow Basic for the HTTPS tunnel
Since Java 8u111, the Basic scheme is disabled by default for HTTPS tunneling: it is listed in the property jdk.http.auth.tunneling.disabledSchemes. The proxy username and password are sent using the Basic scheme, so on https sites a request without this setting will fail authentication even though the credentials are correct. Oracle's networking documentation confirms that HttpClient respects this property too.
Oracle suggests re-enabling Basic by setting the property to an empty value on the command line:
# allow Basic for the HTTPS tunnel
javac ProxyCheck.java
java -Djdk.http.auth.tunneling.disabledSchemes="" ProxyCheckSites on http:// use a different property, jdk.http.auth.proxying.disabledSchemes, and Basic is not disabled in it by default. So the typical picture of “http sites open through the proxy, https ones don't” almost always means someone forgot about -Djdk.http.auth.tunneling.disabledSchemes.
If changing the launch parameters is inconvenient (for example, a third-party script starts the program), turn on the IP whitelist in your plan. Then the proxy doesn't ask for a password, and you need neither the Authenticator nor the property.
Step 4. Check the program output
Run ProxyCheck with the command above. The program prints the IP the site sees your request coming from. Compare it with your machine's address: it should be different. Another run on port 823 gives a new address; on a sticky port, the same one.
The browser page What is my IP shows the browser's IP, not the JVM's, so it tells you nothing about Java. To check the proxy string separately from the code, paste it into the proxy checker.
Step 5. SOCKS5 via java.net.Proxy
The HttpClient documentation only describes working with HTTP and HTTPS proxies through ProxySelector; SOCKS support is not described there. For SOCKS5, Java has a proven route: a java.net.Proxy of type Proxy.Type.SOCKS and URL.openConnection(Proxy). Such a proxy applies only to that connection and, according to the documentation, takes priority over the system ProxySelector.
import java.io.InputStream;
import java.net.*;
public class SocksCheck {
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (!"SOCKS5".equals(getRequestingProtocol())) {
return null;
}
return new PasswordAuthentication("USERNAME", "PASSWORD".toCharArray());
}
});
Proxy socks = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("gw.prokso.com", 824));
URLConnection con = URI.create("https://api.ipify.org").toURL().openConnection(socks);
con.setConnectTimeout(15000);
con.setReadTimeout(30000);
try (InputStream in = con.getInputStream()) {
System.out.println(new String(in.readAllBytes()));
}
}
}For SOCKS5, Java calls the Authenticator with the protocol SOCKS5, which is why the example checks getRequestingProtocol(). The Proxy.Type.SOCKS type covers both SOCKS4 and SOCKS5, and the version is set by the socksProxyVersion property, which defaults to 5.
An alternative to an Authenticator is the java.net.socks.username and java.net.socks.password properties: Java uses them if no authenticator is installed. Otherwise it substitutes the OS user name with no password, and the proxy refuses.
System properties: a proxy for the whole JVM
You can switch a third-party library that makes requests internally to the proxy using JVM properties, without changing code:
| Property | What it sets | Value for Prokso |
|---|---|---|
http.proxyHost / http.proxyPort | Proxy for http:// | gw.prokso.com / 823 or sticky |
https.proxyHost / https.proxyPort | Proxy for https:// | gw.prokso.com / the same port |
http.nonProxyHosts | What goes direct (separated by |), the same list for HTTPS | Defaults to localhost, 127.*, [::1] |
socksProxyHost / socksProxyPort | SOCKS proxy for sockets | gw.prokso.com / 824 |
java.net.useSystemProxies | Take the proxy from the OS | Checked only once at startup |
The username and password for an HTTP proxy can't be set with properties: you still need Authenticator.setDefault or the IP whitelist. Explicitly set http.proxyHost and similar properties take priority over system settings, even if java.net.useSystemProxies is on. HttpClient without a call to proxy() also reads these properties through the default selector.
What the errors mean in Java
- HttpConnectTimeoutException - the connection to the proxy could not be made within
connectTimeout. Check the host and port;HttpClientwon't work on port 824. See proxy timeout. - HttpTimeoutException - there was a connection, but the response didn't arrive in time. Increase the request
timeoutor retry the request: on 823 the retry goes out from a different address. - Authentication fails on https but works on http - Basic is disabled for the tunnel; go back to step 3.
- Access denied with the correct password - check the plan's remaining traffic: when it runs out, the proxy responds the same way as to a wrong password (code 407).
- Connection refused on SOCKS - a mistake in the port or protocol (more details).
Repeated authentication attempts in HttpClient are limited by the jdk.httpclient.auth.retrylimit property (3 by default), so a wrong password won't put the program in a loop.
If the proxy does not work
FAQ
Why don't https sites open through the proxy while http sites do?
Since Java 8u111, Basic authentication is disabled for the HTTPS tunnel by the jdk.http.auth.tunneling.disabledSchemes property. Launch the JVM with -Djdk.http.auth.tunneling.disabledSchemes="" or turn on the IP whitelist in your plan.
Can java.net.http.HttpClient work with SOCKS5?
SOCKS support is not described in the HttpClient documentation. For SOCKS5 use a SOCKS-type java.net.Proxy with URL.openConnection or a socket, as in step 5.
How do I give each thread its own IP?
Create several HttpClient clients, each with its own sticky port from the 10000-20000 range, and assign a client to each thread. The client is thread-safe, so one client can be shared between threads, but then they will share an address.
How many concurrent requests can a plan handle?
Up to 1000 concurrent connections per plan. If your thread pool is larger, some connections will wait or be refused - size the pool to the limit.
Can I do without an Authenticator?
Yes, with the IP whitelist: add the external address of the server running the JVM to your plan's whitelist (up to 5 addresses). Then the proxy doesn't ask for a password, and the tunnel property isn't needed either.
Was this guide helpful?
Thanks for your feedback!
Sorry about that. Tell us which step you got stuck on and we will help.