i am trying to use the system.setproperty to set the proxy in my computer.
Expand|Select|Wrap|Line Numbers
- 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
Expand|Select|Wrap|Line Numbers
- 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