hello everyone.
i am trying to use the system.setprope rty to set the proxy in my computer.
IF YOU run this code you will find that the proxy has been changed from direct to http and the host and the port will be as it is specified in the code.
after you run it the first time please comment the following line of code
and run the program again.
you will find that the proxy returned to Direct.
i need to know how can i set save the changes i added to system.property so all the browsers will use this proxy.
kind regards
hsn
i am trying to use the system.setprope rty to set the proxy in my computer.
Code:
public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("http.proxyHost","192.222.222.2"); System.setProperty("http.proxyPort","808"); System.setProperty("http.nonProxyHosts","yahoo.com"); detect2(); } public static void detect2() { try { //System.setProperty("java.net.useSystemProxies","true"); List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")); for (Iterator iter = l.iterator(); iter.hasNext(); ) { Proxy proxy = (Proxy) iter.next(); System.out.println("proxy type : " + proxy.type()); InetSocketAddress addr = (InetSocketAddress) proxy.address(); if(addr == null) { System.out.println("No Proxy"); } else { System.out.println("proxy hostname : " +addr.getHostName()); System.out.println("proxy port : " +addr.getPort()); } } } catch (Exception e) { e.printStackTrace(); } } public static void detect(String location) { String proxyHost; int proxyPort; try { ProxyInfo info[] = ProxyService.getProxyInfo(new URL(location)); if(info != null && info.length>0) { proxyHost = info[0].getHost(); proxyPort = info[0].getPort(); System.out.println("PROXY = " + proxyHost + ":" + proxyPort); } } catch (Exception ex) { System.err.println("could not retrieve proxy configuration, attempting direct connection." + ex); } }
after you run it the first time please comment the following line of code
Code:
System.setProperty("http.proxyHost","192.222.222.2"); System.setProperty("http.proxyPort","808"); System.setProperty("http.nonProxyHosts","yahoo.com");
you will find that the proxy returned to Direct.
i need to know how can i set save the changes i added to system.property so all the browsers will use this proxy.
kind regards
hsn
Comment