[英]POST Request, no Getting response on retrofit 2
I'm using retrofit 2 whit OkHttpClient into my Android app. 我在我的Android应用中使用了改造2的OkHttpClient。 It's a POST request.
这是一个POST请求。
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. 它通常可以正常工作,但有时我无法获得正确的http响应。
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.
如您所见,没有“ <-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 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?? 拜托,有什么建议吗?
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 只需更正响应并发送我没有关注的类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.