使用URLConnection读取Web的数据时,有些奇怪的网址会严重超时!!
//教育网的可以测试下这个网址http://www.scutde.edu.cn/long time1,time2;
try{
URL url=new URL("http://www.scutde.edu.cn/");
URLConnection con=url.openConnection();
con.setConnectTimeout(3000);
con.setReadTimeout(3000);
time1=System.currentTimeMillis();
con.connect();
time2=System.currentTimeMills();
System.out.println("连接通花费的时间"+(time2-time1)+"ms");
}catch(Exception ex){
time2=System.currentTimeMills();
System.out.println("连接不通花费时间 "+(time2-time1)+"ms");}
为何有很多连接了数十秒后才报告IOException?狂晕.........
这是怎么一回事呢?
能否解决呢?
//教育网的可以测试下这个网址http://www.scutde.edu.cn/long time1,time2;
try{
URL url=new URL("http://www.scutde.edu.cn/");
URLConnection con=url.openConnection();
con.setConnectTimeout(3000);
con.setReadTimeout(3000);
time1=System.currentTimeMillis();
con.connect();
time2=System.currentTimeMills();
System.out.println("连接通花费的时间"+(time2-time1)+"ms");
}catch(Exception ex){
time2=System.currentTimeMills();
System.out.println("连接不通花费时间 "+(time2-time1)+"ms");}
为何有很多连接了数十秒后才报告IOException?狂晕.........
这是怎么一回事呢?
能否解决呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货