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();
}
[]
更多精彩
赞助商链接