Untitled
plain_text
2 months ago
1.2 kB
1
Indexable
Never
public class ApiClient { private static final String BASE_URL = "http://172.16.54.30/cgi-bin/"; private static Retrofit retrofit; public static Retrofit getClient() { if (retrofit == null) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .addInterceptor(chain -> { okhttp3.Request original = chain.request(); String credentials = Credentials.basic("admin", "admin"); okhttp3.Request request = original.newBuilder() .header("Authorization", credentials) .method(original.method(), original.body()) .build(); return chain.proceed(request); }) .build(); retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .build(); } return retrofit; }