Rafael
Rafael

Reputation: 185

POST Request, no Getting response on retrofit 2

I'm using retrofit 2 whit OkHttpClient into my Android app. It's a POST request.

Request must be Synchronous.

This is the code:
ResultObject<Integer, List<OrderResult>> resultcall =
                restclient.getApiService().createUpdateOrders(companyId,                
                orderList).execute().body();

It usually works fine but sometimes I don't get ok http response.

This is the normal response log:

06-08 11:35:56.609 24584 25168 D OkHttp  : --> POST http://93.90.20.171:8080/tpv/rest/order/create?companyId=1 http/1.1
06-08 11:35:56.609 24584 25168 D OkHttp  : Content-Type: application/json; charset=UTF-8
06-08 11:35:56.609 24584 25168 D OkHttp  : Content-Length: 644
06-08 11:35:56.609 24584 25168 D OkHttp  : Connection: 
06-08 11:35:56.609 24584 25168 D OkHttp  : --> END POST
06-08 11:36:03.139 24584 25168 D OkHttp  : <-- 200 OK http://93.90.20.171:8080/tpv/rest/order/create?companyId=1 (6530ms)
06-08 11:36:03.139 24584 25168 D OkHttp  : Server: Apache-Coyote/1.1
06-08 11:36:03.139 24584 25168 D OkHttp  : Content-Type: application/json;charset=UTF-8
06-08 11:36:03.139 24584 25168 D OkHttp  : Date: Thu, 08 Jun 2017 09:36:05 GMT
06-08 11:36:03.139 24584 25168 D OkHttp  : Transfer-Encoding: chunked
06-08 11:36:03.139 24584 25168 D OkHttp  : <-- END HTTP

And this is the error log. As you can see there is no "<-- 200 OK" line and I don'd get any error log.

06-08 11:36:03.219 24584 25168 D OkHttp  : --> POST http://93.90.20.171:8080/tpv/rest/order/create?companyId=1 http/1.1
06-08 11:36:03.219 24584 25168 D OkHttp  : Content-Type: application/json; charset=UTF-8
06-08 11:36:03.219 24584 25168 D OkHttp  : Content-Length: 604
06-08 11:36:03.219 24584 25168 D OkHttp  : Connection: 
06-08 11:36:03.219 24584 25168 D OkHttp  : --> END POST
06-08 11:36:10.089 24584 24584 V ActivityThread: updateVisibility : ActivityRecord{6082a59 token=android.os.BinderProxy@463ef68 {com.six.and.cbo/com.six.and.cbo.OrdercomunnicationTabWidget}} show : true
06-08 11:36:16.343 24584 24584 D ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=2
06-08 11:37:11.634 24584 24584 I ORDERLISTVIEW: --> OnResume

Please, any suggestion??

Upvotes: 0

Views: 646

Answers (1)

Naser Khoshfetrat
Naser Khoshfetrat

Reputation: 152

you can do this instead of executing the call

 call.enqueue(new Callback<List<OrderResult>>() {
            @Override
            public void onResponse(Call<List<OrderResult>> call, Response<List<OrderResult>> response) {
          // do something
            }

            @Override
            public void onFailure(Call<List<OrderResult>> call, Throwable t) {
                Log.e("call failed", t.toString());
                Toast.makeText(getApplicationContext(), "call faild ", Toast.LENGTH_LONG).show();
            }
        });

just correct the response and send type i didnt focused on it

Upvotes: 1

Related Questions