解决方案 »
- listview问题求助
- andriod自带email如何支持html邮件发送?
- ListView怎么才能让指定的item disable和enable呢?
- 帮助
- 关于安卓mysql数据库
- apk能实现动态编译吗
- Handler.postDelayed和View.postDelayed有何区别
- 如将将onDraw()方法中的canvas保存到bitmap中?
- 上下文菜单没出来,不解,求大神指点(照着android编程权威指南做的)
- android里ViewGroup的子View大小计算
- android自动挂载多个USB设备
- 请问android如何让父窗口上背景的长宽 自动适应 和它上面子窗口所占长宽的大小一样呢?
String str = getContent(httpResponse);方法:
public static String getContent(HttpResponse response) { BufferedReader in = null;
String page = "";
try {
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
while ((line = in.readLine()) != null) {
sb.append(line);
}
page = sb.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return page;
}
我没遇到过你那样的问题,不过你可以试试这个方法
试了试楼上的方法不行换成了HttpUrlConnection解决了问题
public String httpGet2(String url2, String paras) throws Exception { // 拼接url
if (paras != null && !paras.equals("")) {
url2 += "?" + paras;
}
URL url = new URL(url2);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000*4);
if (conn.getResponseCode() == 200) {
InputStream is = conn.getInputStream();
// 将输入流转换成字符串
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String json = baos.toString();
baos.close();
is.close();
//
return json;
}
return "获取数据失败";
}