private String getTestContent(String url) {
HttpGet httpRequest = new HttpGet(url);
String result = null;
BufferedReader br = null;
InputStream is = null;
try {
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
int response = httpResponse.getStatusLine().getStatusCode();
if (response == 200) {
HttpEntity entity = httpResponse.getEntity();
StringBuffer sb = new StringBuffer();
is = entity.getContent();
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String data = "";
boolean found = false;
while ((data = br.readLine()) != null) {
if(data != null && data.indexOf(TEST_CONTENT_START_TAG) != -1) {
found = true;
}
else {
if (found) {
if ((data!=null) && (data.indexOf(TEST_CONTENT_END_TAG)!=-1)) {
found = false;
break;
}
sb.append(data);
sb.append("\n");
}
}
}
result = sb.toString();
return result;
} else {
return result;
}
} catch (ClientProtocolException e) {
return null;
} catch (HttpHostConnectException e) {
return null;
} catch (UnknownHostException e) {
return null;
} catch (IOException e) {
return null;
} catch (Exception e) {
return null;
} finally {
if(is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
HttpGet httpRequest = new HttpGet(url);
String result = null;
BufferedReader br = null;
InputStream is = null;
try {
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
int response = httpResponse.getStatusLine().getStatusCode();
if (response == 200) {
HttpEntity entity = httpResponse.getEntity();
StringBuffer sb = new StringBuffer();
is = entity.getContent();
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String data = "";
boolean found = false;
while ((data = br.readLine()) != null) {
if(data != null && data.indexOf(TEST_CONTENT_START_TAG) != -1) {
found = true;
}
else {
if (found) {
if ((data!=null) && (data.indexOf(TEST_CONTENT_END_TAG)!=-1)) {
found = false;
break;
}
sb.append(data);
sb.append("\n");
}
}
}
result = sb.toString();
return result;
} else {
return result;
}
} catch (ClientProtocolException e) {
return null;
} catch (HttpHostConnectException e) {
return null;
} catch (UnknownHostException e) {
return null;
} catch (IOException e) {
return null;
} catch (Exception e) {
return null;
} finally {
if(is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
解决方案 »
- 我想做这么一个应用,大家帮分析一下有多少难点?
- 关于GridView选中行置顶
- Android中使用intent进行页面跳转,运行时出现异常
- 监听器的OnCheckedChangeListener方法无法重写,@Override编译错误
- 请问怎么将 ListView 每一行距离变小 默认的实在太大了
- 新人求前辈指教。
- 获取手机号码归属地代码
- 请推荐android voip入门书
- list自定义item 怎么插入
- 手机root了 怎么修改系统文件 实现充电就开机
- 急急急----PAD端如何正确的显示WORD和EXCEL表单的样式
- android setBackGround()方法不兼容4.1以下版本
因为线程直接操作UI不安全,现在的语言都不支持在线程中操作UI!