DefaultHttpClient execute() 方法报错
来源:互联网 发布:php debug pack 编辑:程序博客网 时间:2024/06/05 21:00
今天写代码,这里报错
public static String doGet(String url, boolean useCache, String encoding)
throws Exception {
if (TextUtils.isEmpty(url)) {
throw new NullPointerException("网络请求地址不能为空");
}
String data = null;
if (useCache) {
data = doGetCache(url);
if (!LFormat.isEmpty(data)) {
return data;
}
}
DefaultHttpClient httpClient = new DefaultHttpClient(getClientParams());
HttpGet httpGet = new HttpGet(url);
if (!LFormat.isEmpty(LApplication.getInstance().getSessionValue())) {
httpGet.setHeader(LApplication.getInstance().getSessionKey(),
LApplication.getInstance().getSessionValue());
}
HttpResponse httpResponse;
httpResponse = httpClient.execute(httpGet); //这里报错
HttpEntity httpEntity = httpResponse.getEntity();
if (httpResponse.getStatusLine().getStatusCode() == 200) {
InputStream inputStream = httpEntity.getContent();
data = convertStreamToString(inputStream, encoding);
if (LFormat.isEmpty(data))
throw new ConnectException(RUNTIME_EXCEPTION);
data = LFormat.JSONTokener(data);
List<Cookie> cookies = httpClient.getCookieStore().getCookies();
for (int i = 0; i < cookies.size(); i++) {
if (LApplication.getInstance().getSessionKey()
.equals(cookies.get(i).getName())) {
LApplication.getInstance().setSessionValue(
cookies.get(i).getValue());
}
}
} else {
throw new ConnectException(RUNTIME_EXCEPTION);
}
if (useCache && !LFormat.isEqual(SEND_ERROR, data)) {
doSetCache(url, data);
}
return data;
}
.解决方法很简单
Manifest清单文件中加上网络协议
<uses-permission android:name="android.permission.INTERNET" />
- DefaultHttpClient execute() 方法报错
- DefaultHttpClient
- DefaultHttpClient
- DefaultHttpClient
- SSIS 无视 Execute Package task 控件的错误, 不会导致整个package报错的方法
- CentOS 报错cannot execute binary file
- symfony报错:Declaration of testAction::execute() must be compatible with sfComponent::execute($request
- Android项目Build报错:Unable to execute dx
- 运行报错:Unable to execute dex: java.nio.BufferOverflowException
- httpclient.execute()不执行也不报错解决办法
- 执行shell脚本报错 cannot execute binary file
- 新建项目报错 Failed to execute aapt
- 报错:Unable to execute dex: Multiple dex files define
- pyinstaller打包运行报错failed to execute script main
- maven项目启动报错:Failed to execute goal......
- 设置DefaultHttpClient和HttpClient的超时时间的方法
- Android studio 进行网络连接时,出现 HttpResponse reponse =new DefaultHttpClient().execute(request)处有错误
- Android Studio 进行网络连接时,出现 HttpResponse reponse =new DefaultHttpClient().execute(request)处有错误
- linux前后台任务切换
- Silverlight 常见错误及解决笔录
- MSP430程序跑飞原因
- struts.xml配置文件(package,namespace,action)
- POJ1546 & HDU 1335 & ZOJ 1334 Basically Speaking(进制转换)
- DefaultHttpClient execute() 方法报错
- 移动同时旋转播放动画
- flushWindowSurfaceColorBuffer 模拟器启动问题
- 应用程序开发总结(10)--存在完美的数学计算
- 管理
- SourceInsight 中文注释空格问题(解决)
- GUI图形用户界面
- 32 Tomcat配置
- Android的5个进程等级