HTT presponse为String的android [英] HttpResponse to String android

查看:89
本文介绍了HTT presponse为String的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐蔽的HTTP响应使用code以下字符串,但我的回应字符串得到终止在中间的任何想法,如何转换的HTTP响应字符串,使我没有得到任何缓冲的问题。

I am trying to covert the http response to string using the code below, but my response string is getting terminated in the middle any ideas, how to convert http response to string so that i dont get any buffer problem.

private static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append((line + "\n"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close(); 
        } catch (IOException e) {
            e.printStackTrace(); 
        }
    }
    return sb.toString();
}

任何人的任何建议,请帮助。 谢谢 Deepesh

Anyone any suggestion please help. Thanks Deepesh

推荐答案

我认为,还有一个更简单的方法:

i think, there is a simpler way:

String result = EntityUtils.toString(resp_entity);

吧?

这篇关于HTT presponse为String的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆