2017-06-08 9 views
0

私はあなたのAndroidアプリにretrofit 2 whit OkHttpClientを使用しています。これはPOSTリクエストです。POSTリクエスト、いいえretrofit 2の回答を得る

リクエストは同期している必要があります。

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

通常正常に動作しますが、ときどき私はokの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

あなただけの応答を修正し、[OK]を、それ

+0

に焦点を当て、私はdidntのタイプを送る代わりに、コール

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

を実行するのでこれを行うことができます。だから私は "onFailure"にエラーが出ると思いますか?しかし、もし私が同期要求をしたいのであれば、どうすればいいのですか? – Rafael

+0

私はこれをしなかったが、それは良いアプローチではないと思う。応答を得るには数時間かかるかもしれないし、UIスレッドを5秒以上ロックするとANRエラーが出るだろう。 –

+0

私はそれを非同期モードに変更するだけで、問題は継続します。要求が10秒を超えています – Rafael

関連する問題