AndroidHttpClient.execute正在恢复HTT presponse为空 [英] AndroidHttpClient.execute is returning httpresponse as null

查看:137
本文介绍了AndroidHttpClient.execute正在恢复HTT presponse为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下面的code访问我的URI

 的AsyncTask AsyncTask的=新的AsyncTask(){        @覆盖
        保护对象doInBackground(对象... PARAMS){
            AndroidHttpClient的HttpClient = AndroidHttpClient.newInstance();
            HttpUriRequest uriGetRequest =新HTTPGET(HTTP://本地主机:8080 / restsql-0.8.6 / RES /);
            HTT presponse HTT presponse = NULL;
            尝试{
                HTT presponse = httpClient.execute(uriGetRequest);
                ;
            }赶上(例外五){
                // TODO自动生成catch块
                如果(E!= NULL){
                Log.e(ModelLoader,e.getMessage(),E);
                }
                Log.e(型号装载机,同时呼吁执行错误);
            }
            返回HTT presponse;
        }
    };
    asyncTask.execute(新对象());

但总是HTT presponse为空。即使没有异常。
我也象 https://google.co.in/ 其做工精细有效的URI检查。
我也从URI的浏览器工作正常。
由于没有抛出的异常,我无法进一步进行。


解决方案

  

在AVD连接到本地主机,你需要使用网址


  http://10.0.2.2/

而不是

 的http://本地主机/

有关参考

I am trying to access my uri from the below code

    AsyncTask asyncTask = new AsyncTask() {

        @Override
        protected Object doInBackground(Object... params) {
            AndroidHttpClient httpClient = AndroidHttpClient.newInstance("");
            HttpUriRequest uriGetRequest = new HttpGet("http://localhost:8080/restsql-0.8.6/res/");
            HttpResponse httpResponse = null;
            try {
                httpResponse = httpClient.execute(uriGetRequest);
                ;
            } catch (Exception e) {
                // TODO Auto-generated catch block
                if(e!=null){
                Log.e("ModelLoader", e.getMessage(), e);
                }
                Log.e("Model Loader", "Error while calling execute");
            }
            return httpResponse;
        }
    };
    asyncTask.execute(new Object());

But always the httpresponse is null. Even no exception is thrown. I have checked with a valid uri like https://google.co.in/ and its working fine. Also my URI from browser is working fine . As there is no exception thrown I am not able to proceed further.

解决方案

In AVD to connect to localhost you need to use url

       http://10.0.2.2/

instead of

        http://localhost/

For reference.

这篇关于AndroidHttpClient.execute正在恢复HTT presponse为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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