Java Http 设置代理

1、今天在Eclipse下面编译一个Http客户端时,发现可以连接局域网,连接不上外部网络,突然想起所用PC是通过代理访问网络的,设置代理后程序可以正常访问网络了:

        Properties props = System.getProperties();  
        props.setProperty("proxySet", "true");  
        props.setProperty("http.proxyHost", "*.*.*.*");  
        props.setProperty("http.proxyPort", "****");  
        Authenticator.setDefault(new Authenticator() {  
            protected PasswordAuthentication getPasswordAuthentication() {  
                return new PasswordAuthentication("****",  
                        new String("****").toCharArray());  
            }  
        });  


原文地址:https://www.cnblogs.com/javawebsoa/p/3239159.html