Android HttpResponse – 已消耗内容

Android HttpResponse – 已消耗内容,第1张

概述当读取HttpResponse时,下面的方法会出现错误:“已消耗内容”.我知道内容只能被消耗一次,但是我在第一次尝试时遇到了这个错误,我在代码中没有看到我可能会消耗它两次. private static String getData(String url, HttpParams params) { StringBuilder builder = new StringBuilder(); 当读取httpResponse时,下面的方法会出现错误:“已消耗内容”.我知道内容只能被消耗一次,但是我在第一次尝试时遇到了这个错误,我在代码中没有看到我可能会消耗它两次.
private static String getData(String url,httpParams params) {    StringBuilder builder = new StringBuilder();        httpClIEnt clIEnt = new DefaulthttpClIEnt();        httpGet httpGet = new httpGet(url);        if (params != null) {            httpGet.setParams(params);        }        String result = "";        try {            httpResponse response = clIEnt.execute(httpGet);            Statusline statusline = response.getStatusline();            int statusCode = statusline.getStatusCode();            if (statusCode == 200) {                httpentity entity = response.getEntity();                inputStream content = entity.getContent();                BufferedReader reader = new BufferedReader(new inputStreamReader(content));                String line;                while ((line = reader.readline()) != null) {                    builder.append(line);                }                content.close();                result = builder.toString();            }         } catch (ClIEntProtocolException e) {            e.printstacktrace();        } catch (IOException e) {            e.printstacktrace();        } catch (Exception e) {            e.printstacktrace();        }    return result;      }
解决方法 这是在模拟器中还是在手机上?它可能是模拟器特定的问题.我在我的设备上测试它,它完美无缺.

您是否有可能正在使用内容的调试器手表?

总结

以上是内存溢出为你收集整理的Android HttpResponse – 已消耗内容全部内容,希望文章能够帮你解决Android HttpResponse – 已消耗内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1131336.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存