Making http call using ion with in intent Service gives error on data network

♀尐吖头ヾ 提交于 2019-12-12 00:22:03

问题


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);
                    }
                }
            });

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."


回答1:


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.

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.



来源:https://stackoverflow.com/questions/33569473/making-http-call-using-ion-with-in-intent-service-gives-error-on-data-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!