安卓:HttpClient的在Android 4.0的API不运行 [英] Android:HttpClient does not run in Android 4.0 API

查看:124
本文介绍了安卓:HttpClient的在Android 4.0的API不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了code它适用于Android 2.2的API,但它并没有在Android 4.0下运行

 字符串的URL = textUrl.getText()的toString()。
     HttpClient的客户端=新DefaultHttpClient();
     HTTPGET请求=新HTTPGET(URL);
     尝试
     {
        HTT presponse响应= client.execute(请求);
        textResult.setText(HttpHelper.request(响应));
     }
     赶上(例外五){
        // TODO:处理异常
         textResult.setText(失败);
    }


解决方案

如果您在安卓2.x的主线程调用的URL那么这将是完美运行。

但HonyCumb其上的版本,你需要发送调用从辅助线程的URL。

您可以使用的AsyncTask 为。

I have written the code it works on Android 2.2 API but it does not work on Android 4.0

 String url = textUrl.getText().toString();
     HttpClient client = new DefaultHttpClient();
     HttpGet  request = new HttpGet(url);
     try
     {
        HttpResponse response = client.execute(request);
        textResult.setText(HttpHelper.request(response));
     }
     catch (Exception e) {
        // TODO: handle exception
         textResult.setText("Failed");
    }

解决方案

If you call the URL from the main thread in android 2.x then it will be perfectly run.

But HonyCumb and its upper version you need to send call the URL from worker thread.

You can use AsyncTask for that.

这篇关于安卓:HttpClient的在Android 4.0的API不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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