码迷,mamicode.com
首页 > 其他好文 > 详细

HttpUrlConntion inputstream

时间:2014-08-11 15:03:32      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:android

try
{
	URL url = new URL(getString(R.string.serverurl));
	HttpURLConnection conn = (HttpURLConnection) url.openConnection();
	conn.setRequestMethod("GET");
	conn.setConnectTimeout(5000);

	int code = conn.getResponseCode();
	if (code == 200)
	{
		InputStream is = conn.getInputStream();
		updateInfo = UpdateInfoParser.getUpdateInfos(is);
		if (updateInfo != null)
		{
			if (getVersion().equals(updateInfo.getVersion()))
			{
				// 版本号相同,进入应用程序主界面
				msg.what = LOAD_MAIN_UI;
			}
			else
			{
				// 版本号不相同,提示用户更新应用程序
				msg.what = SHOW_UPDATE_INFO;
			}
		}
		else
		{
			// 解析xml失败
			msg.what = XML_PARSE_ERROR;
		}
	}
	else
	{
		// 服务器错误,资源没找到
		msg.what = SERVER_ERROR;
	}
}
catch (MalformedURLException e)
{
	e.printStackTrace();
	msg.what = URL_ERROR;
}
catch (IOException e)
{
	e.printStackTrace();
	msg.what = NETWORK_ERROR;
}

HttpUrlConntion inputstream,布布扣,bubuko.com

HttpUrlConntion inputstream

标签:android

原文地址:http://blog.csdn.net/feecooling/article/details/38492335

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!