2017-12-01 1 views
0

인터셉터 내부의 특정 요청을 가로 채려고합니다. 나는 또한 페이로드에 특정 필드를 확인해야하고 나는이 페이로드를 검색하는 방법을 찾을 수없는 그러나HTTP 인터셉터에서 JSON 페이로드를 검색하는 방법은 무엇입니까?

response.code() 

을 쉽게 수행 할 401 개 HTTP 상태를 잡으려면.

Interceptor authorizationInterceptor = new Interceptor() { 
    @Override 
    public Response intercept(Chain chain) throws IOException { 
     Request request = chain.request(); 
     okhttp3.Response response = chain.proceed(request); 

     if (response.code() == 401) { 
      // I need to access the payload here 
      return response; 
     } 

     return response; 
    } 
}; 

디버거는 페이로드는 응답 내부 사용할 수 있음을 알 수 :

여기 내 인터셉터입니다. enter image description here

검색 할 수 있습니까? Selvin에 의해 제안

+1

를 사용 (문자열로) 검색 할 수 있습니다(). 문자열을()'? 반응의 몸을 소모 할 것이라고 기억합니다. – Selvin

+0

@Selvin 그것은 내가 필요한 감사합니다. – Louis

답변

0

는, 몸은 무엇 response.body`에 대해

response.body().string() 
관련 문제