HttpURLConnection设置代理

设置全局代理,JVM范围内有效:
        System.getProperties().put("proxySet", "true");   
        System.getProperties().put("proxyHost", "proxy.xxx.com");   
        System.getProperties().put("proxyPort", "8080"); 


对单一连接设代理:
URL url = new URL(urlStr);
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
        "proxy.xxx.com", 8080));
        HttpURLConnection urlc = (HttpURLConnection) url.openConnection(proxy);

你可能感兴趣的:(java,jvm)