在Intent Service中使用ion进行http调用会在数据网络上产生错误 [英] Making http call using ion with in intent Service gives error on data network

查看:96
本文介绍了在Intent Service中使用ion进行http调用会在数据网络上产生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用intentService与Ion进行http调用.在Wifi上效果很好,但是当我切换到数据网络时,事情开始崩溃.

I am using intentService for making http calls with Ion. On Wifi it works well but when I switch to data network things start breaking.

Ion.with(Application.getApplicationContext())
            .load(url)
            .as(new TypeToken<Object>() {})
            .withResponse()
            .setCallback(new FutureCallback<Response<Object>>() {
                @Override
                public void onCompleted(Exception e, Response<Object> response) {
                    if(e == null) {
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("result", (Serializable) response.getResult());
                        rec.send(response.getHeaders().code(), bundle);
                    }
                }
            });

以上是我在IntentService中使用的代码 我正进入(状态 "java.io.IOException:非2xx状态行:HTTP/1.1 500内部服务器错误."

Above is the code which i am using in IntentService I am getting "java.io.IOException:non 2xx status line:HTTP/1.1 500 internal server error."

推荐答案

由于您正在使用意图服务,因此onHandleIntent方法一旦完成,该服务就会终止. Ion的请求将检测到服务上下文已终止并取消该请求.

Since you are using an intent service, as soon the onHandleIntent method completes, the service will terminate. Ion's request will detect the service context is terminated and cancel the request.

但是,似乎您正在使用主应用程序上下文,而不是服务上下文,在这种情况下它应该可以工作.无论如何,您都会得到正确的响应(500仍然是成功的请求和响应). 500表示问题出在服务器端.

However, it seems you are using the main application context, rather than the service context, in which case it should work. In any case, you are getting a correct response (500 is still successful request and response). The 500 indicates the issue is server side.

这篇关于在Intent Service中使用ion进行http调用会在数据网络上产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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