我想写个程序,通过http代理(可用)访问外网
可程序报错:连接超时
报错如下:java.net.ConnectException: Operation timed out: connect
程序代码如下:
import java.net.*;
import java.util.Properties;
import java.io.*;public class OpenUrl { public static void main(String args[]) {
try {
String strUrl = "http://blog.csdn.net/cqq/";
URL url = new URL(strUrl);
URLConnection conn = url.openConnection(); String strProxy = "***。***。***。***";//代理服务器
String strPort = "8080";
String ss = "";
Properties systemProperties = System.getProperties();
systemProperties.setProperty("proxyHost", strProxy);
systemProperties.setProperty("proxyPort", strPort); BufferedReader rd = new BufferedReader(new InputStreamReader(conn
.getInputStream())); while ((ss = rd.readLine()) != null) {
System.out.println(ss);
}
rd.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}