编写Java application时,如何设置proxy的信息

发表于:2007-06-22来源:作者:点击数: 标签:

   
  若在java application中访问外部网站,首先应设置proxy信息,样例代码如下:

import java.util.properties;
.....
Properties sys = System.getProperties();
sys.put("proxySet","true");

sys.put("proxyHost","myHTTP.proxyserver.com");
sys.put("proxyPort","80");
System.setProperties(sys);
u = new URL(website);
connect = (HttpURLConnection)u.openConnection();
.....

原文转自:http://www.ltesting.net