How to Configure Network Settings in Java


Setting the proxy server and port:

System.setProperty("http.proxyHost", "");

System.setProperty("http.proxyPort", "80");

For an HTTPS proxy, just change 'http' to 'https' for each property.

Or you can just use the system's proxies:

System.setProperty("", "true");

IP Protocol

Disabling the IPv6 stack and forcing IPv4:

System.setProperty("" , "true");

Use IPv6 addresses when possible:

System.setProperty("" , "true");


Setting a SOCKS proxy:

System.setProperty("socksProxyHost" , "");

System.setProperty("socksProxyPort" , "1080")

Specify the SOCKS protocol used by the server:

System.setProperty("socksProxyVersion" , "4");

Authenticating with a SOCKSv5 proxy server:

System.setProperty("" , "myusername");

System.setProperty("" , "mypassword");


Setting a TrustStore that was created with keytool:

System.setProperty("", "/path/to/truststore");

Misc. Properties

Set the string sent in the User-Agent request header in HTTP requests:

System.setProperty("http.agent", "foobar");

Keep in mind that this new string will have "Java/" appended at the end. So the example above would yield "foobar Java/1.6.0" if the current Java version being used is 1.6.0.

Prevent persistent connections:

System.setProperty("http.keepalive", "false");

Set the maximum number of idle connections that will be kept alive (http.keepalive must be true):

System.setProperty("http.maxConnections", "5");

Set the maximum number of redirects that will be followed for an HTTP request:

System.setProperty("http.maxRedirects", "20");
Last Updated: July 4th, 2023
Was this article helpful?

Improve your dev skills!

Get tutorials, guides, and dev jobs in your inbox.

No spam ever. Unsubscribe at any time. Read our Privacy Policy.

© 2013-2024 Stack Abuse. All rights reserved.