读书人

Java_设立HTTP代理

发布时间: 2012-09-22 21:54:54 作者: rapoo

Java_设置HTTP代理

/**如果有代理设置所使用 * @param host 代理地址 * @param port 端口 * @param username 用户名 * @param password 密码 */public static void initProxy(String host, int port, final String username,final String password) {Authenticator.setDefault(new Authenticator() {protected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication(username,new String(password).toCharArray());}});System.setProperty("http.proxyPort", Integer.toString(port));System.setProperty("http.proxyHost", host);}

读书人网 >编程

热点推荐