package com.example.okhttp;
import android.util.Log;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class LogIntercept implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request=chain.request();
long curTime =System.currentTimeMillis();
Log.i("TAG","intercept: REQUEST="+ request.toString());
Response response=chain.proceed(request);
Log.i("TAG","intercept: REQUEST="+ response.toString());
Log.i("TAG","intercept:耗时="+(System.currentTimeMillis() - curTime) + "ms");
return response;
}
}
okHttpclient = new OkHttpClient.Builder()
.addInterceptor(new LogIntercept())
.build();