use of okhttp3.CookieJar in project okhttp by square.
the class URLConnectionTest method connectViaHttpsReusingConnections.
private void connectViaHttpsReusingConnections(boolean rebuildClient) throws Exception {
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse().setBody("this response comes via HTTPS"));
server.enqueue(new MockResponse().setBody("another response via HTTPS"));
// The pool will only reuse sockets if the SSL socket factories are the same.
SSLSocketFactory clientSocketFactory = sslClient.socketFactory;
RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
CookieJar cookieJar = new JavaNetCookieJar(new CookieManager());
ConnectionPool connectionPool = new ConnectionPool();
urlFactory.setClient(new OkHttpClient.Builder().cache(cache).connectionPool(connectionPool).cookieJar(cookieJar).sslSocketFactory(clientSocketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build());
connection = urlFactory.open(server.url("/").url());
assertContent("this response comes via HTTPS", connection);
if (rebuildClient) {
urlFactory.setClient(new OkHttpClient.Builder().cache(cache).connectionPool(connectionPool).cookieJar(cookieJar).sslSocketFactory(clientSocketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build());
}
connection = urlFactory.open(server.url("/").url());
assertContent("another response via HTTPS", connection);
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(1, server.takeRequest().getSequenceNumber());
}
use of okhttp3.CookieJar in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class ServiceGenerator method createService.
public static <S> S createService(Class<S> serviceClass, Context context) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
}
PersistentCookieStore cookieStore = new PersistentCookieStore(context);
java.net.CookieManager cookieManager = new java.net.CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder().cookieJar(new JavaNetCookieJar(cookieManager)).addInterceptor(logging).addNetworkInterceptor(new StethoInterceptor());
Gson gson = new GsonBuilder().setLenient().create();
Retrofit retorfit = new Retrofit.Builder().baseUrl(MafiaRemoteService.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient.build()).build();
return retorfit.create(serviceClass);
}
use of okhttp3.CookieJar in project WeexErosFramework by bmfe.
the class AxiosManager method createClient.
public OkHttpClient createClient(Context context, long timeout) {
CookieJarImpl cookieJar = new CookieJarImpl(new BMPersistentCookieStore(context));
OkHttpClient.Builder builder = new OkHttpClient.Builder().addInterceptor(new LoggerInterceptor("TAG")).connectTimeout(timeout == 0 ? 3000L : timeout, TimeUnit.MILLISECONDS).readTimeout(timeout == 0 ? 30000L : timeout, TimeUnit.MILLISECONDS).cookieJar(cookieJar);
if (DebugableUtil.isDebug()) {
builder.addNetworkInterceptor(new WeexOkhttp3Interceptor());
}
return builder.build();
}
use of okhttp3.CookieJar in project MiMangaNu by raulhaag.
the class BatoTo method testLogin.
// just log in batoto to store the cookie if all ok
@Override
public boolean testLogin(String user, String password) throws Exception {
Navigator nav = getNavigatorAndFlushParameters();
CookieJar ccj = nav.getHttpClient().cookieJar();
VolatileCookieJar cj = new VolatileCookieJar();
nav.setCookieJar(cj);
String data = nav.get(HOST + "/forums/index.php?app=core&module=global&section=login");
HashMap<String, String> params = Navigator.getFormParamsFromSource(data);
nav = getNavigatorAndFlushParameters();
nav.addPost("auth_key", params.get("auth_key"));
nav.addPost("ips_password", password);
nav.addPost("ips_username", user);
nav.addPost("referer", "https://bato.to/forums/");
nav.addPost("rememberMe", "1");
nav.post(HOST + "/forums/index.php?app=core&module=global§ion=login&do=process");
List<Cookie> cookies = Navigator.getCookieJar().loadForRequest(HttpUrl.parse("https://bato.to"));
nav.setCookieJar(ccj);
return cj.contain("member_id");
}
use of okhttp3.CookieJar in project GzuClassSchedule by mnnyang.
the class app method initOkHttp.
private void initOkHttp() {
OkHttpClient okHttpClient = new OkHttpClient.Builder().followSslRedirects(false).cookieJar(// 为OkHttp设置自动携带Cookie的功能
new LocalCookieJar()).addInterceptor(new LoggerInterceptor("TAG")).cookieJar(// 要在内存Cookie前
new CookieJarImpl(new PersistentCookieStore(getBaseContext()))).cookieJar(// 内存Cookie
new CookieJarImpl(new MemoryCookieStore())).build();
OkHttpUtils.initClient(okHttpClient);
}
Aggregations