What to use instead of sun.net.www.protocol.http.HttpURLConnection.userAgent?

httpurlconnection, java

Solution

By default that variable is defined as follows:

String javaVersion = "Java/" + System.getProperty("java.version");
String userAgent = System.getProperty("http.agent") == null ? javaVersion : System.getProperty("http.agent") + " " + javaVersion;

So you can replace that variable with this one or with the name of your application or with any other string you like (since the resulting string is not the User-Agent of a common browser I assume that no JavaScript or any other code will check for it).

Problem

I receive this warning [javac] SSLTunnelSocketFactory.java:120: warning: sun.net.www.protocol.http.HttpURLConnection is Sun proprietary API and may be removed in a future release [javac] + sun.net.www.protocol.http.HttpURLConnection.userAgent for ``` if(NetworkUtils.isIPV6Compatible()&& NetworkUtils.isValidIPV6Address(host)){ msg = "CONNECT [" + host + "]:" + port + " HTTP/1.0\n" + "User-Agent: " + sun.net.www.protocol.http.HttpURLConnection.userAgent + "\r\n\r\n"; } ``` Do you have an idea what can I use instead (preferably not a an external jar but from the installed JVM)?

Original source