简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM