2017-06-08 48 views
0

我使用改进2惠氏OkHttpClient到我的Android应用程序。这是一个POST请求。POST请求,没有获得对改造的反应2

请求必须是同步的。

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

它通常工作正常,但有时我不确定http响应。

这是正常的反应日志:

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 

这是错误日志。正如你可以看到没有“< - 200 OK”行,我不会得到任何错误日志。

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 [email protected] {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 

请问,有什么建议?

回答

1

你可以做到这一点,而不是执行调用

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

只需要修正的响应,并发送类型我没有专注于这

+0

确定。那么你认为我可以在“onFailure”中遇到错误?但是如果我想要做一个同步请求,我应该怎么做? – Rafael

+0

我没有这样做,但我认为这不会是一个好方法,因为获取响应可能需要几次,如果您锁定UI线程超过5秒钟,您将收到ANR错误。 –

+0

我只是将其更改为异步模式,问题继续,任何其他建议?请求大于10秒 – Rafael