use of okhttp3.logging.HttpLoggingInterceptor in project instagram-java-scraper by postaddictme.
the class AuthenticatedInstaTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
Credentials credentials = new Credentials();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
client = new Instagram(httpClient);
client.basePage();
client.login(credentials.getLogin(), credentials.getPassword());
client.basePage();
}
use of okhttp3.logging.HttpLoggingInterceptor in project instagram-java-scraper by postaddictme.
the class AuthenticatedInstaTest method testLoginWithInvalidCredentials.
@Test(expected = InstagramAuthException.class)
public void testLoginWithInvalidCredentials() throws Exception {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient httpClient = new OkHttpClient.Builder().addNetworkInterceptor(loggingInterceptor).addInterceptor(new FakeBrowserInterceptor(UserAgents.OSX_CHROME)).addInterceptor(new ErrorInterceptor()).cookieJar(new DefaultCookieJar(new CookieHashSet())).build();
Instagram instagramClient = new Instagram(httpClient);
instagramClient.basePage();
instagramClient.login("1", "2");
}
use of okhttp3.logging.HttpLoggingInterceptor in project keleFanfou by kelefun.
the class BaseRetrofit method retrofit.
public static Retrofit retrofit(String baseUrl, Interceptor interceptor) {
OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
// 打印请求日志
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
okHttpBuilder.addInterceptor(logging);
// 添加拦截器
if (interceptor != null) {
okHttpBuilder.addInterceptor(interceptor);
}
OkHttpClient okHttpClient = okHttpBuilder.build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create()).client(okHttpClient).build();
return retrofit;
}
use of okhttp3.logging.HttpLoggingInterceptor in project ListenerMusicPlayer by hefuyicoder.
the class NetworkModule method provideLastFMRetrofit.
@Provides
@Named("lastfm")
@PerApplication
Retrofit provideLastFMRetrofit() {
String endpointUrl = Constants.BASE_API_URL_LASTFM;
Gson gson = new GsonBuilder().create();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
// OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
return retrofit;
}
use of okhttp3.logging.HttpLoggingInterceptor in project ListenerMusicPlayer by hefuyicoder.
the class NetworkModule method provideKuGouRetrofit.
@Provides
@Named("kugou")
@PerApplication
Retrofit provideKuGouRetrofit() {
String endpointUrl = Constants.BASE_API_URL_KUGOU;
Gson gson = new GsonBuilder().create();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
// OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
return retrofit;
}
Aggregations