I need the condition of setting no proxy in my application; for that I used the following code:
URL url = null;
try {
url = new URL(uri.toURL().toString());
} catch (MalformedURLException e3) {
e3.printStackTrace();
}
try {
//client = (HttpURLConnection) url.openConnection(java.net.Proxy.NO_PROXY);
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.nonProxyHosts",ServerIP);
systemProperties.setProperty( "proxySet", "false" );
systemProperties.setProperty("http.proxyHost","");
systemProperties.setProperty("http.proxyPort","");
URLConnection conn = url.openConnection(Proxy.NO_PROXY);
conn.connect();
} catch (IOException e3) {
e3.printStackTrace();
}
But I got network unreachable exception!!
Any help!!
If I do not misunderstand your question… You want to connect to server directly when it is connecting via WIFI ?
p.s. Please note that the code snippet above may miss some error handling. Thanks 😉