Search in sources :

Example 56 with HttpLoggingInterceptor

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();
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) FakeBrowserInterceptor(me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) BeforeClass(org.junit.BeforeClass)

Example 57 with HttpLoggingInterceptor

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");
}
Also used : CookieHashSet(me.postaddict.instagram.scraper.cookie.CookieHashSet) OkHttpClient(okhttp3.OkHttpClient) ErrorInterceptor(me.postaddict.instagram.scraper.interceptor.ErrorInterceptor) DefaultCookieJar(me.postaddict.instagram.scraper.cookie.DefaultCookieJar) FakeBrowserInterceptor(me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Test(org.junit.Test)

Example 58 with HttpLoggingInterceptor

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;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 59 with HttpLoggingInterceptor

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;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache) Named(javax.inject.Named) PerApplication(io.hefuyi.listener.injector.scope.PerApplication) Provides(dagger.Provides)

Example 60 with HttpLoggingInterceptor

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;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache) Named(javax.inject.Named) PerApplication(io.hefuyi.listener.injector.scope.PerApplication) Provides(dagger.Provides)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)107 OkHttpClient (okhttp3.OkHttpClient)87 Provides (dagger.Provides)27 Retrofit (retrofit2.Retrofit)25 GsonBuilder (com.google.gson.GsonBuilder)24 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)16 File (java.io.File)15 Response (okhttp3.Response)15 IOException (java.io.IOException)14 Gson (com.google.gson.Gson)13 Interceptor (okhttp3.Interceptor)11 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 LoggingInterceptor (com.toshi.manager.network.interceptor.LoggingInterceptor)6 List (java.util.List)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 FakeBrowserInterceptor (me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor)5 ResponseBody (okhttp3.ResponseBody)5 BeforeClass (org.junit.BeforeClass)5