public static void refresh(String location){
/** 网络的url地址 */
URL url = null;
/** http连接 */
HttpURLConnection httpConn = null;
try{
url=new URL(location);
httpConn=(HttpURLConnection)url.openConnection();// 打开连接
HttpURLConnection.setFollowRedirects(true);
}
catch(Exception e){
e.printStackTrace();
}
finally{
httpConn.disconnect();
}红色部分返回一个HttpURLConnection连接,我想知道url指向的域名的服务器崩溃了,导致访问不成功,我如何知道? 因为它只是返回一个HttpURLConnection连接,而没有告诉我连接究竟成功还是不成功
/** 网络的url地址 */
URL url = null;
/** http连接 */
HttpURLConnection httpConn = null;
try{
url=new URL(location);
httpConn=(HttpURLConnection)url.openConnection();// 打开连接
HttpURLConnection.setFollowRedirects(true);
}
catch(Exception e){
e.printStackTrace();
}
finally{
httpConn.disconnect();
}红色部分返回一个HttpURLConnection连接,我想知道url指向的域名的服务器崩溃了,导致访问不成功,我如何知道? 因为它只是返回一个HttpURLConnection连接,而没有告诉我连接究竟成功还是不成功
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货