天天看點

錯誤 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: closed 解決方案

Retrofit 的使用參考,可以在這裡檢視 http://blog.csdn.net/aka_GZ/article/details/52447777

按照網上配置請求之并未成功拿到資料,

檢視錯誤資訊後發現出現這個異常 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: closed

經過排查,原因是因為在攔截器裡面  ,列印了請求體,有說法是, response.body() 隻能調用一次,再次調用會出現狀态異常

看來想列印請求資訊,需要另求它法了

//網絡攔截器
client.networkInterceptors().add(new Interceptor() {
    @Override
    public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
        Request request=chain.request();
        com.squareup.okhttp.Response response = chain.proceed(request);

        Log.e("weiquan",""+request.httpUrl()+" "+request.headers()+"  "+response.body().string());
        return response;
    }

});      

繼續閱讀