Java System Properties
Quick Reference Guide


http.agent Java System Property

The http.agent Java System Property accepts a string to use as as prefix in the user agent of HTTP requests.

Default Value

Java/x.y.z

Where x.y.z is the Java version number.

Overview of http.agent

Sets a prefix value to use as a User-Agent http request header value to use When a HTTP or HTTPS request is made via an api provided by the Java SDK (HttpsURLConnection or URL.openStream()).

For example if your Java Version is 11.0.15, the default user agent would be:

User-Agent: Java/11.0.15

However if you set -Dhttp.agent=MyUserAgent then the user agent value would be:

User-Agent: MyUserAgent Java/11.0.15

Related System Properties

Here are some other networking Java system properties:

Supported Since

Java has supported the http.agent system property since at least version 1.5, support may go back to even older versions of java.

Setting http.agent on Startup

You can set the http.agent java system property during startup of the java runtime using the -D command line argument:

java -Dhttp.agent=MyUserAgent MyAppMain

You may also be able to specify http.agent via the JAVA_TOOL_OPTIONS environment variable:

JAVA_TOOL_OPTIONS=-Dhttp.agent=MyUserAgent

Setting / Reading http.agent at Runtime

You can set http.agent at runtime with the following Java code:

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

WARNING: Depending on the property and JVM version using setProperty may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the http.agent system property may be cached within an internal private static variable of the implementing class.

To read the value of http.agent at runtime, you can use this Java code:

String propertyValue = System.getProperty("http.agent");
if (propertyValue != null) {
    System.out.println("http.agent = " + propertyValue);
} else {
    System.out.println("http.agent was null");
}