AndroidHttpClient关闭后无法getEntity().getContent()

AndroidHttpClient关闭后无法getEntity().getContent(),第1张

概述public InputStream getInputStream() { AndroidHttpClient client = AndroidHttpClient.newInstance(USERAGENT); HttpUriRequest request = new HttpGet(url); InputStream in = null; try {
public inputStream getinputStream() {    androidhttpclient clIEnt = androidhttpclient.newInstance(USERAGENT);    httpUriRequest request = new httpGet(url);    inputStream in = null;    try {        httpResponse response = clIEnt.execute(request);        in = response.getEntity().getContent();        return in;    } catch (IOException e) {        e.printstacktrace();    } finally {        clIEnt.close();    }}

我把这个方法放在Util类中.
但是当在另一个类中调用getinputStream()时,由于androidhttpclient被关闭,我无法获得inputSteam.
如果我没有关闭androidhttpclient,就会出现“发现泄漏,androidhttpclient已创建且从未关闭”.
如何在这种情况下获取内容

解决方法 像这样,例如:

public inputStream getinputStream() {    androidhttpclient clIEnt = androidhttpclient.newInstance(USERAGENT);    httpUriRequest request = new httpGet(url);    inputStream in = null;    try {        httpResponse response = clIEnt.execute(request);        return new ByteArrayinputStream(new EntityUtils.toByteArray(response.getEntity()));    } catch (IOException e) {        e.printstacktrace();    } finally {        clIEnt.close();    }}
总结

以上是内存溢出为你收集整理的AndroidHttpClient关闭后无法getEntity().getContent()全部内容,希望文章能够帮你解决AndroidHttpClient关闭后无法getEntity().getContent()所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1128964.html

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

发表评论

登录后才能评论

评论列表(0条)

保存