android asynchttpclient 编码,【已解决】Android中使用Android Asynchronous Http Client结果无法执行到onSuccess函数...

博主在使用Android AsynchronousHttpClient在Android 4.2环境下进行网络请求时遇到问题,尝试更换网址和响应处理器但未执行onSuccess。最终发现是配置和环境设置导致在UI线程请求异常。
摘要由CSDN通过智能技术生成

【问题】

折腾:

的过程中,去写了代码:String strSongUrl = "http://www.songtaste.com/song/" + strUrlOrId;

AsyncHttpClient client = new AsyncHttpClient();

//client.get("http://www.google.com", new AsyncHttpResponseHandler() {

client.get(strSongUrl, new AsyncHttpResponseHandler() {

@Override

public void onSuccess(String response) {

System.out.println(response);

}

});

但是结果调试了半天,也没有执行到对应的那行:

System.out.println(response);

即,没有执行到onSuccess函数。

【解决过程】

1.又换了换其他网址:String strSongUrl = "http://www.songtaste.com/song/" + strUrlOrId;

String baiduUrl = "http://www.baidu.com";

AsyncHttpClient client = new AsyncHttpClient();

//client.get("http://www.google.com", new AsyncHttpResponseHandler() {

//client.get(strSongUrl, new AsyncHttpResponseHandler() {

client.get(baiduUrl, new AsyncHttpResponseHandler() {

@Override

public void onSuccess(String response) {

System.out.println(response);

}

});

结果问题依旧。根本没法执行到onSuccess。

2.网上找了半天,也看到了:

但是很明显,我这里就是普通的string,所以应该用AsyncHttpResponseHandler而不是JsonHttpResponseHandler,但是结果就是运行不到onSuccess。

其中,我当前所用AVD是Android 4.2的。

3.也看了之前的某个解释,说是只有访问网络,返回的状态码是200时,才会执行到onSuccess函数的。

但是此处,不知道为何,始终无法执行到对应的onSuccess。

【总结】

原因未知。

貌似是Android Asynchronous Http Client和Android 4.2不够兼容?

感觉也不像啊。

【后记】

结果后来证实,实际上是之前一些参数配置,环境设置,没弄好,导致与在当前的UI线程中,去访问网络,所以出现异常了,所以无法正常返回,所以才无法执行到onSuccess的。

关于如何正确配置,使得可以访问网络,抓取网页,详情可参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值