因为在内网中使用代理访问外网,最近要求写个小工具抓取外网页面。因此需要为URlConnection设置代码,代码很简单,如下,做个记号。 package org.tencent.corey; import java.util.Properties; import com.tencent.vw.searcher.net.ContentCatcher; import com.tencent.vw.searcher.net.IContentCatcher; public class ProxyDemo { public static void main(String[] args)throws Exception{ String proxyHost = "web-proxy.oa.com"; String proxyPort = "8080"; Properties prop = System.getProperties(); prop.put("http.proxyHost", proxyHost); prop.put("http.proxyPort", proxyPort); IContentCatcher catcher=new ContentCatcher(); String str=catcher.getContentFromURL("http://wap.3g.cn/","utf-8"); System.out.println(str); } }