java使用代理服务器访问网络
2009-05-25 15:00
295 查看
Properties prop = System.getProperties();
//设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", "10.10.0.96");
//设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", "8080");
//设置不需要通过代理服务器访问的主机,可以使用*通配符,多个地址用|分隔
prop.setProperty("http.nonProxyHosts", "localhost|10.10.*");
//设置安全访问使用的代理服务器地址与端口
//它没有https.nonProxyHosts属性,它按照http.nonProxyHosts 中设置的规则访问
prop.setProperty("https.proxyHost", "10.10.0.96");
prop.setProperty("https.proxyPort", "443");
//使用ftp代理服务器的主机、端口以及不需要使用ftp代理服务器的主机
prop.setProperty("ftp.proxyHost", "10.10.0.96");
prop.setProperty("ftp.proxyPort", "2121");
prop.setProperty("ftp.nonProxyHosts", "localhost|10.10.*");
//socks代理服务器的地址与端口
prop.setProperty("socksProxyHost", "10.10.0.96");
prop.setProperty("socksProxyPort", "1080");
//设置登陆到代理服务器的用户名和密码
Authenticator.setDefault(new MyAuthenticator(uid, pwd));
class MyAuthenticator extends Authenticator {
private String user = "";
private String password = "";
public MyAuthenticator(String user, String password) {
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
//设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", "10.10.0.96");
//设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", "8080");
//设置不需要通过代理服务器访问的主机,可以使用*通配符,多个地址用|分隔
prop.setProperty("http.nonProxyHosts", "localhost|10.10.*");
//设置安全访问使用的代理服务器地址与端口
//它没有https.nonProxyHosts属性,它按照http.nonProxyHosts 中设置的规则访问
prop.setProperty("https.proxyHost", "10.10.0.96");
prop.setProperty("https.proxyPort", "443");
//使用ftp代理服务器的主机、端口以及不需要使用ftp代理服务器的主机
prop.setProperty("ftp.proxyHost", "10.10.0.96");
prop.setProperty("ftp.proxyPort", "2121");
prop.setProperty("ftp.nonProxyHosts", "localhost|10.10.*");
//socks代理服务器的地址与端口
prop.setProperty("socksProxyHost", "10.10.0.96");
prop.setProperty("socksProxyPort", "1080");
//设置登陆到代理服务器的用户名和密码
Authenticator.setDefault(new MyAuthenticator(uid, pwd));
class MyAuthenticator extends Authenticator {
private String user = "";
private String password = "";
public MyAuthenticator(String user, String password) {
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
相关文章推荐
- java使用代理服务器访问网络
- java中使用代理访问网络的几种方法
- 1.使用java.net.URL类访问网络数据
- java中通过代理服务器(PRoxy)访问网络
- Java中使用代理访问网络及验证
- 【java】快速访问http网络请求框架QuickHttp的使用
- Java使用URLConnection类访问网络资源
- java使用代理访问网络的几种方法
- Jamendo 使用java.net.URL类访问网络数据
- Android5.0以上使用XUtils访问网络出现错误: java.io.IOException: stack size 1036KB
- Java 网络编程(三) 创建和使用URL访问网络上的资源
- JavaSE第一百零七讲:使用Java网络API访问远程服务器
- java使用代理访问网络的几种方法
- Android5.0以上使用XUtils访问网络出现错误或者网络数据无法加载: java.io.IOException: stack size 1036KB
- Java 网络编程(三) 创建和使用URL访问网络上的资源
- java使用代理访问网络
- java使用代理访问网络
- java使用代理访问网络
- java使用smb访问网络共享文件
- Java 网络编程(三) 创建和使用URL访问网络上的资源