我在我的Android应用中使用改装2 whit OkHttpClient。这是一个POST请求。
请求必须是同步的。
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
这是错误日志。你可以看到没有&#34;&lt; - 200 OK&#34;并且我没有得到任何错误日志。
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
请,任何建议??
答案 0 :(得分: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();
}
});
只需更正响应并发送我没有专注于它的类型