use of okhttp3.CookieJar in project java-sdk by watson-developer-cloud.
the class WatsonCookieJar method loadForRequest.
/*
* (non-Javadoc)
*
* @see okhttp3.CookieJar#loadForRequest(okhttp3.HttpUrl)
*/
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
List<Cookie> cookies = this.adapter.loadForRequest(url);
// TODO: Removes the SESSIONID for speech to text session lest requests
if (url.encodedPathSegments().contains(SPEECH_TO_TEXT) && !url.encodedPathSegments().contains(SESSIONS)) {
List<Cookie> sessionLessCookies = new ArrayList<Cookie>();
for (Cookie cookie : cookies) {
if (!cookie.name().equalsIgnoreCase(SESSIONID)) {
sessionLessCookies.add(cookie);
}
}
cookies = sessionLessCookies;
}
return cookies;
}
use of okhttp3.CookieJar in project AndroidFrame by tongxiaoyun.
the class m method initNetWorkWithCookie.
/**
* 初始化网络控制器
*/
public m initNetWorkWithCookie(Context context) {
// 持久化存储cookie
ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
// log拦截器
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// 自定义OkHttp
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).cookieJar(// 设置开启cookie
cookieJar).addInterceptor(// 设置开启log
logging).build();
netUtils = new MyOkHttp(okHttpClient);
return instance;
}
use of okhttp3.CookieJar in project okhttputils by hongyangAndroid.
the class MyApplication method onCreate.
@Override
public void onCreate() {
super.onCreate();
ClearableCookieJar cookieJar1 = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
// CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(10000L, TimeUnit.MILLISECONDS).readTimeout(10000L, TimeUnit.MILLISECONDS).addInterceptor(new LoggerInterceptor("TAG")).cookieJar(cookieJar1).hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager).build();
OkHttpUtils.initClient(okHttpClient);
}
use of okhttp3.CookieJar in project okhttp by square.
the class UrlConnectionCacheTest method cachePlusCookies.
@Test
public void cachePlusCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
urlFactory.setClient(urlFactory.client().newBuilder().cookieJar(cookieJar).build());
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=FIRST").addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=SECOND").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
URL url = server.url("/").url();
assertEquals("A", readAscii(urlFactory.open(url)));
cookieJar.assertResponseCookies("a=FIRST; path=/");
assertEquals("A", readAscii(urlFactory.open(url)));
cookieJar.assertResponseCookies("a=SECOND; path=/");
}
use of okhttp3.CookieJar in project okhttp by square.
the class CacheTest method cachePlusCookies.
@Test
public void cachePlusCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
client = client.newBuilder().cookieJar(cookieJar).build();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=FIRST").addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=SECOND").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
HttpUrl url = server.url("/");
assertEquals("A", get(url).body().string());
cookieJar.assertResponseCookies("a=FIRST; path=/");
assertEquals("A", get(url).body().string());
cookieJar.assertResponseCookies("a=SECOND; path=/");
}
Aggregations