Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 943
Charlie Brown Avatar asked Sep 06 '25 03:09

Charlie Brown


1 Answers

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).

like image 74
Pino Avatar answered Sep 07 '25 23:09

Pino