WEB开发网
开发学院手机开发Android 开发 Android判断一个连接是否成功 阅读

Android判断一个连接是否成功

 2010-05-24 16:31:00 来源:WEB开发网   
核心提示:try {URL url = new URL(“http://”+params[0]);HttpURLConnection urlc = (HttpURLConnection) url.openConnection();urlc.setRequestProperty(“User-Agent”, “Android App

try {

URL url = new URL(“http://”+params[0]);

HttpURLConnection urlc = (HttpURLConnection) url.openConnection();

urlc.setRequestProperty(“User-Agent”, “Android Application:”+Z.APP_VERSION);

urlc.setRequestProperty(“Connection”, “close”);

urlc.setConnectTimeout(1000 * 30); // mTimeout is in seconds

urlc.connect();

if (urlc.getResponseCode() == 200) {

Main.Log(“getResponseCode == 200″);

return new Boolean(true);

}

} catch (MalformedURLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Tags:Android 判断 一个

编辑录入:coldstar [复制链接] [打 印]
赞助商链接