使用org.apache.http的http相关类,导致应用崩溃。
在android studio 环境下接入图灵机器人的api,我另外开了一个线程来处理网络数据的读取。在使用另一个调用了org.Apache.http的 几个类时,显示 HttpClient ,HttpGet,HttpResponse,HttpEntity 都已经过时(即一条横线划掉类名)。而且程序在点击按钮(触发与网络端读取数据的交互动作)的时候,程序崩溃。我再logcat里面发现是doInBackground类进入异常抛出,以下是相关的主要代码部分:
private HttpClient mHttpClient;
private HttpGet mhttpGet;
private HttpResponse mHttpResponse;
private HttpEntity mHttpEntity;
@Override
protected String doInBackground(String... params) {
try{
mHttpClient = new DefaultHttpClient();
mhttpGet = new HttpGet(url);
mHttpResponse = mHttpClient.execute(mhttpGet);
mHttpEntity = mHttpResponse.getEntity();
in = mHttpEntity.getContent();
System.out.println("**********************"); //调试信息,未被打印
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null){
sb.append(line);
}
return sb.toString();
}catch (Exception e){ //有异常
System.out.println("################################"); //调试信息,该条调试信息在logcat中被打出
}
return null;
}
我再网上搜了一下,发现有几个朋友说这个在模拟器测试不行,但在2.3手机上测试正常,在4.X手机测试失败。都不知道原因。所以请大神帮忙答疑解惑,小板凳长期等候解答。
相关推荐
log4j配置文件基本含义说明
log4j配置文件基本含义说明
bootstrap-fileinput+strtus2实现多文件上传,导入马上能跑
包括了原生request的获得
Apache并发数、带宽限制
限制并发数 下载模块: 到官方网址:http://www.nowhere-land.org/programs/mod_vhost_limit/下载模块 http://www.nowhere-land.org/prog ... st_limit-0.4.tar.gz 安装: apxs -c mod_vhost_limit.c -o /path/to/libexec/mod_vhost_limit.so 在 httpd.conf加入: LoadModule vhost_limit_module libexec/mod_vhost_limit.so AddModule mod_vhost_limit.c
java使用apache+resin实现负载均衡设置
java使用apache+resin实现负载均衡设置
apache openssl配置快速的https网站
启动WEB服务 apachectl start 关闭WEB服务 apachectl stop 启用VHosts Include conf/extra/http-vhost.conf 授予目录权限 注释 Deny from all 或者增加Directory授权 启用SSL I nclude conf/extra/https-ssl.conf 配置SSL DocumentRoot … ScriptAlias … SSLCertificateFile /data/gauss/soft/httpd-2.2.4/conf/cert/server.crt SSLCertificateKeyFile /data/gauss/soft/httpd-2.2.4/conf/cert/server.key SSLCertificateChainFile /data/gauss/soft/httpd-2.2.4/conf/cert/intermediate.crt 启用HTTP1.1 注释或者修改BrowserMatch 启用SSI …shtml… AddOutputFilter INCLUDES .shtml 设置默认页面 DirectoryIndex index.html index.shtml….


