public class LoginIntercepter implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request build = chain.request().newBuilder()
.addHeader("token","123")
.addHeader("haha","haha")
.build();
return chain.proceed(build);
}
}
OkHttpClient build = new OkHttpClient.Builder()
.addInterceptor(new LoginIntercepter())
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
Request build1 = new Request.Builder()
.url("http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1")
.get()
.build();
build.newCall(build1).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string = response.body().string();
Log.i(TAG, "onResponse: "+string);
}
});