public class ServiceProxy
{
private ServiceProxy(){ } static public String request(URL url) throws IOException
{
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
InputStreamReader inReader = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(inReader);
StringBuffer sb = new StringBuffer();
String line;
while((line = br.readLine()) != null)
{
sb.append(line);
sb.append("\n");
}
return sb.toString();
}
static public void main(String[] args)
{
try
{
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost","192.168.0.50");
systemProperties.setProperty("http.proxyPort","808");
String content=ServiceProxy.request(new URL("www.163.com"));
System.out.println("content="+content);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}注意设置代理服务器