Retrofitヘッダブロック
1199 ワード
public class HttpUtils {
public final Api api;
private HttpUtils() {
OkHttpClient client = new OkHttpClient.Builder().addNetworkInterceptor(new logging()).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Contast.url)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(client)
.build();
api = retrofit.create(Api.class);
}
//
class logging implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request.Builder builder = chain.request().newBuilder().addHeader("source", "android");
Log.d("xxxxxx", "request:" + request);
Response proceed = chain.proceed(request);
return proceed;
}
}
private static class GetDataNet{
private static HttpUtils httpUtils=new HttpUtils();
}
public static HttpUtils getdatanet(){
return GetDataNet.httpUtils;
}
}