public String get(String url) throws Exception {
if (is != null) {
int count = 0;
// 返回内容
s = new String(baos.toByteArray());
}
return s;
}
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
// 尝试读取entity的长度,返回-1表示长度未知long length = entity.getContentLength();
InputStream is = entity.getContent();
String s = null;if (is != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[512];
int ch = -1;int count = 0;
while ((ch = is.read(buf)) != -1) {
baos.write(buf, 0, ch);
count += ch;}
Log.e("HttpTask", "length=" + baos.toByteArray().length);// 返回内容
s = new String(baos.toByteArray());
}
return s;
}