2017-09-08 10 views
0

좋은 상태 코드와 json 데이터 결과를 가진 서버에서 첫 번째 성공적인 응답을 얻습니다 .4 개의 연속 요청이 trigged되고 모두 나쁜 결과를 낳습니다 응답 (상태 코드 400) 메시지가 잘못된 요청. 새로 고침 레이아웃을 눌러 서버에서 데이터 목록을 가져 오려고하면이 이상한 동작이 발생합니다. 요청 : 이 내 코드입니다첫 번째 성공적인 응답을 얻은 후 서버의 이상한 serie 응답

public static void loadMyOrders(Context context, final OrdersCallBack listener) { 
     KService kTestService = ApiUtils.getOrdersApiService(context); 
    // TODO to be changed to getMyOrders <Done> 
    KService.getAllTheOrders().enqueue(new Callback<List<OrderServer>>() { 
     @Override 
     public void onResponse(Call<List<OrderServer>> call, 
           Response<List<OrderServer>> response) { 
      if (response.code() == 400) { 
       try { 
        Log.d("Error code 400",response.errorBody().string()); 
       } catch (IOException e) { 
        e.printStackTrace(); 
        Log.d("IO exception"," " + e.getMessage()); 

       } 
      } 
      if (response.isSuccessful()) { 
       Log.d("listenerServerManager", response.code() + " "); 
       Log.d("slist0::" , " "+ response.body().toString()); 
       List<OrderServer> ordersList = response.body(); 
       for (OrderServer orderFromServer : ordersList) { 
        orderFromServer.compoundPrimaryKey(); 
       } 
       Log.d("slist1::" , " "+ ordersList.toString()); 
       listener.onSuccesful(ordersList); 
      } else { 
       Log.d("listenerServerManager", response.code() + " "); 
      listener.onError(response.code() + " "); 
      } 

     } 

     @Override 
     public void onFailure(Call<List<OrderServer>> call, Throwable t) { 
      Log.d("listenerServerManager", t.getMessage()+ " "); 
      listener.onError(t.getMessage() + " "); 

     } 
    }); 
} 

개조 클라이언트 :

public static Retrofit getClient(String baseUrl, Context context) { 
     sharedpreferences = context.getSharedPreferences(GlobalsManager.USERPREFERENCES, context.MODE_PRIVATE); 
       final String token = sharedpreferences.getString(GlobalsManager.TOKENKEY, " "); 
       Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() { 
        @Override public boolean shouldSkipField(FieldAttributes f) { 
         return f.getDeclaringClass().equals(RealmObject.class); 
        } 
        @Override public boolean shouldSkipClass(Class<?> clazz) { 
         return false; 
        } 
       }).create(); 
       HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 
       if (httpClient == null) { 
        httpClient = new OkHttpClient.Builder().addNetworkInterceptor(new StethoInterceptor()); 
       } 
        httpClient.addInterceptor(new Interceptor() { 
         @Override public okhttp3.Response intercept(Chain chain) throws IOException { 
          Request request = chain.request() 
           .newBuilder() 
           .addHeader("Authorization", "Bearer " + token) 
           .addHeader("Cache-Control", "no-cache") 
           .addHeader("Content-Type", "application/json") 
           .build(); 
           return chain.proceed(request); 
         } 
        }); 
       httpClient.addInterceptor(loggingInterceptor); 
        //httpClient.retryOnConnectionFailure(true); 
        return new Retrofit.Builder().baseUrl(baseUrl) 
         .addConverterFactory(GsonConverterFactory.create(gson)) 
         .client(httpClient.build()) 
         .build(); 
       } 

이것은 출력 : 첫 번째 응답이 성공은 내가 4 succesvies 응답을 얻기 코드 응답으로 400.

 09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: <-- 200 OK http://api.serverapitest.kproj.net/api/TransportOrders/all (533ms) 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Server: nginx/1.10.3 (Ubuntu) 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Date: Fri, 08 Sep 2017 15:39:39 GMT 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Content-Type: application/json; charset=Windows-1252 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Content-Length: 32443 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Connection: keep-alive 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Cache-Control: no-cache 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Pragma: no-cache 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: Expires: -1 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: X-AspNet-Version: 4.0.30319 
    09-08 16:39:38.121 11246-13196/com.kProject.app6 D/OkHttp: X-Powered-By: ASP.NET 
    09-08 16:39:38.341 11246-13196/com.kProject.app6 D/OkHttp: [{THE GOOD LIST : THE EXPETED *******DATA *****************]} 
09-08 16:39:38.351 11246-13196/com.kProject.app6 D/OkHttp: <-- END HTTP (32443-byte body) 
    <<<<<<After the refresh layout is pressed>>>>>> 
    09-08 16:40:45.151 11246-11246/com.kProject.app6 D/token-retrofitclient: FKJHGFHFGDKJHFDGFEZUOFbNR2Rt-AJu6mT_1Ci7QQAWYGiKH84M6lyAS*****DnpWWFdbo4nOGWfxTKVbA-RO2TzZjbZ5Sqn7_Da-UBm8mcc9x1JKQ6q8KWshd6 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: --> GET http://api.serverapitest.kproj.net/api/TransportOrders/all http/1.1 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Authorization: Bearer Liv27WIlooXjkjdQ7bNR2Rt-AJu6mT_1Ci7QQAWYGiKH84M6lyASB0RXMiq2WRAB8zx85N7IFSu1CyphJcXGMjArS876Tj_EjYoDkec4Uu6UubiOKid2wG6ta80t0y6ejlp0FECHmqm6llav7uj_W-Au11JLXCmlICOMXT8j8dzCnVBJtr7Uc5oUA6bLMAONOqyU_nKEwz2ZUtRAIIiImY_qzNvc49NSqm7RTqSvBzJha8ElIz515PRWhFfbOaGx-U7jn1-JE7vTSJXfPGCOCGU53ecvO13AFlX2ckG3bUDMUzkqcn534PprTYMgYggGGQf48qdu1SJMgkuyoHJ_81YfDmG8Kr_smrhc7tyoR3wdUQCX_zsVBMJ-zlAPDkNfk15DG4c0qWzmuW9pZZMR5AaAveKU6KUCyUrikFlDGGvwsMLL9P9iYRlZqHFw_3lDu7DnpWWFdbo4nOGWfxTKVbA-RO2TzZjbZ5Sqn7_Da-UBm8mcc9x1JKQ6q8KWshd6 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Cache-Control: no-cache 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: --> END GET 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: --> GET http://api.serverapitest.kproj.net/api/TransportOrders/all http/1.1 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Authorization: Bearer Liv27WIlooXjkjdQ7bNR2Rt-AJu6mT_1Ci7QQAWYGiKH84M6lyASB0RXMiq2WRAB8zx85N7IFSu1CyphJcXGMjArS876Tj_EjYoDkec4Uu6UubiOKid2wG6ta80t0y6ejlp0FECHmqm6llav7uj_W-Au11JLXCmlICOMXT8j8dzCnVBJtr7Uc5oUA6bLMAONOqyU_nKEwz2ZUtRAIIiImY_qzNvc49NSqm7RTqSvBzJha8ElIz515PRWhFfbOaGx-U7jn1-JE7vTSJXfPGCOCGU53ecvO13AFlX2ckG3bUDMUzkqcn534PprTYMgYggGGQf48qdu1SJMgkuyoHJ_81YfDmG8Kr_smrhc7tyoR3wdUQCX_zsVBMJ-zlAPDkNfk15DG4c0qWzmuW9pZZMR5AaAveKU6KUCyUrikFlDGGvwsMLL9P9iYRlZqHFw_3lDu7DnpWWFdbo4nOGWfxTKVbA-RO2TzZjbZ5Sqn7_Da-UBm8mcc9x1JKQ6q8KWshd6 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Cache-Control: no-cache 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Authorization: Bearer Liv27WIlooXjkjdQ7bNR2Rt-AJu6mT_1Ci7QQAWYGiKH84M6lyASB0RXMiq2WRAB8zx85N7IFSu1CyphJcXGMjArS876Tj_EjYoDkec4Uu6UubiOKid2wG6ta80t0y6ejlp0FECHmqm6llav7uj_W-Au11JLXCmlICOMXT8j8dzCnVBJtr7Uc5oUA6bLMAONOqyU_nKEwz2ZUtRAIIiImY_qzNvc49NSqm7RTqSvBzJha8ElIz515PRWhFfbOaGx-U7jn1-JE7vTSJXfPGCOCGU53ecvO13AFlX2ckG3bUDMUzkqcn534PprTYMgYggGGQf48qdu1SJMgkuyoHJ_81YfDmG8Kr_smrhc7tyoR3wdUQCX_zsVBMJ-zlAPDkNfk15DG4c0qWzmuW9pZZMR5AaAveKU6KUCyUrikFlDGGvwsMLL9P9iYRlZqHFw_3lDu7DnpWWFdbo4nOGWfxTKVbA-RO2TzZjbZ5Sqn7_Da-UBm8mcc9x1JKQ6q8KWshd6 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: Cache-Control: no-cache 
    09-08 16:40:45.161 11246-14427/com.kProject.app6 D/OkHttp: --> END GET 
    09-08 16:40:45.181 11246-11246/com.kProject.app6 D/ViewRootImpl: #1 mView = android.widget.LinearLayout{76d391e V.E...... ......I. 0,0-0,0} 
    09-08 16:40:45.201 11246-11373/com.kProject.app6 D/mali_winsys: new_window_surface returns 0x3000, [399x132]-format:1 
    09-08 16:40:45.261 11246-11373/com.kProject.app6 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <-- 400 Bad Request http://api.serverapitest.kproj.net/api/TransportOrders/all (222ms) 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Server: nginx/1.10.3 (Ubuntu) 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Date: Fri, 08 Sep 2017 15:40:46 GMT 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Content-Type: text/html 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Content-Length: 182 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Connection: close 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <html> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <head><title>400 Bad Request</title></head> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <body bgcolor="white"> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <center><h1>400 Bad Request</h1></center> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <hr><center>nginx/1.10.3 (Ubuntu)</center> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: </body> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: </html> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <-- END HTTP (182-byte body) 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <-- 400 Bad Request http://api.serverapitest.kproj.net/api/TransportOrders/all (224ms) 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Server: nginx/1.10.3 (Ubuntu) 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Date: Fri, 08 Sep 2017 15:40:46 GMT 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Content-Type: text/html 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Content-Length: 182 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: Connection: close 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <html> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <head><title>400 Bad Request</title></head> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <body bgcolor="white"> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <center><h1>400 Bad Request</h1></center> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <hr><center>nginx/1.10.3 (Ubuntu)</center> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: </body> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: </html> 
    09-08 16:40:45.391 11246-14427/com.kProject.app6 D/OkHttp: <-- END HTTP (182-byte body) 
    09-08 16:40:45.401 11246-11246/com.kProject.app6 D/Error code 400: <html>                  <head><title>400 Bad Request</title></head>                  <body bgcolor="white">                  <center><h1>400 Bad Request</h1></center>                  <hr><center>nginx/1.10.3 (Ubuntu)</center>                  </body>                  </html> 
+1

이 유 ..이 나쁜 요청이 발생하는 이유를 볼 필요가 귀하의 유와 요청을 데이터가 잘되지 않는 한이 백엔드 뭔가의 안부 보인다 .. –

+0

실제 요청을 제공하십시오. –

+0

이것은 빠르게 연속해서 발생하며 서버가 속도 제한을 행사하고 있습니까? –

답변

0

내 경우 서버가 이러한 요청을 처리 할 수 ​​없었습니다. HTTP 클라이언트가 정적이 아니라면 정적 클라이언트를 제거하십시오. 그렇지 않으면 기존 요청도 새 요청과 함께 만들어 서버가 모든 요청을 동시에 처리 할 수 ​​없도록 만듭니다. 다음은 필요한 경우를 대비 한 설정입니다.

public WebServiceInterface getNetworkService(@Nullable final String token, @NonNull final String url) throws IOException { 
     this.token = token; 
     this.url = url; 
     return getRetrofit(url).create(WebServiceInterface.class); 
    } 

    private Retrofit getRetrofit(String url) { 
     OkHttpClient.Builder client = 
       new OkHttpClient.Builder(). 
         addInterceptor(interceptor). 
         connectTimeout(90, TimeUnit.SECONDS). 
         writeTimeout(90, TimeUnit.SECONDS). 
         readTimeout(90, TimeUnit.SECONDS); 

     if (!Constant.RELEASE) { 
      client.addInterceptor(getLogger()); 
     } 

     retrofit.baseUrl(url) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 
       .client(client.build()); 
     return retrofit.build(); 
    } 
+0

고맙지 만 작동하지 않습니다. –