编写的java程序访问网络,结果因为公司代理服务器。设置了properties,还是不行,程序如下:
1 import java.io.*; 2 import java.net.*; 3 import java.util.Properties; 6 public class renren { 7 public static void main(String[] args)throws IOException{ 8 { 9 URL url=new URL("http://baike.baidu.com/"); 10 String strProxy="192.168.10.147"; 11 String strPort="8080"; 12 Properties systemProperties=System.getProperties(); 13 systemProperties.setProperty("http.proxyHost", strProxy); 14 systemProperties.setProperty("http.proxyPort", strPort); 15 16 InputStreamReader isr=new InputStreamReader(url.openStream()); 17 BufferedReader br=new BufferedReader(isr); 18 19 while(br.readLine()!=null) 20 System.out.println(br.readLine()); 21 } 23 } 25 }
问题出在哪?
看oracle的tutorials
http://docs.oracle.com/javase/tutorial/essential/environment/properties.html
一是看不太懂,更谈不上进一步运行了。英语加油加油。
键 值:变量名?
properties vs configuration
服务器的ip地址给错了,改为:proxy.psh.com.cn
然后报407错误。需要添加服务器验证,加入用户名与密码
1 Authenticator.setDefault( 2 new Authenticator() { 3 public PasswordAuthentication getPasswordAuthentication() { 4 return new PasswordAuthentication( 5 strName, strPwd.toCharArray()); 6 } 7 } 8 );
关于这些,怎么样深入地学习?
http.proxyHost:networking properties
http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html
新词:identical explicitly implicitly initiate