解决方案 »
- Android Null Pointer的问题
- ListView控件使用的一些问题
- android与Windows Mobile兼容问题
- 怎么在一个辅助类启动service啊?????
- 请问Android中支持那些JSR?能给一个列表吗?
- Android老油条请进
- android调用webservice 不执行envelope.bodyIn
- 关于 startActivity() 方法调用问题
- android之Gallery图库学习
- 求助!eclipse logcat报错什么意思
- 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 "获取数据失败";
}