*****JAVA设置代理服务器访问网页(100分)*****
JAVA怎样设置代理服务器访问网页?
1、不想用第三方软件包,光是java.net.*
2、类似
String sUrl = "http://www.baidu.com ";
Properties prop = System.getProperties();
prop.put( "proxySet ", "true ");
prop.put( "proxyHost ", ...);
prop.put( "proxyPort ", "80 ");
System.setProperties(prop);
try {
URL su = new URL(sUrl);
System.out.println( "url: " + su);
URLConnection uc = su.openConnection();
System.out.println( "uc: " + uc);
InputStream is = su.openStream();
System.out.println( "ic: " + is.read());
is.close();
System.out.println( "ok ");
} catch (Exception e) {
e.printStackTrace();
}
3、设置用户名和密码。(身份认证)
------解决方案--------------------帮忙顶
------解决方案--------------------帮忙顶
------解决方案--------------------不想用第三方,那就根据代理协议自己实现喽
------解决方案--------------------HttpURLConnection不是可以代理吗?
------解决方案--------------------up
------解决方案--------------------lz 都没说是什么代理....有没有防火墙,等等
------解决方案--------------------Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( "username ", "password ".toCharArray());
}
});