use of okhttp3.Cookie in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method removeCookie.
@OnClick(R.id.removeCookie)
public void removeCookie(View view) {
HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
cookieStore.removeCookie(httpUrl);
showToast("详细移除cookie的代码,请看demo的代码");
}
use of okhttp3.Cookie in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method getAllCookie.
@OnClick(R.id.getAllCookie)
public void getAllCookie(View view) {
//一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
List<Cookie> allCookie = cookieStore.getAllCookie();
showToast("所有cookie如下:" + allCookie.toString());
}
use of okhttp3.Cookie in project okhttp-OkGo by jeasonlzy.
the class CookieActivity method getCookie.
@OnClick(R.id.getCookie)
public void getCookie(View view) {
//一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
List<Cookie> cookies = cookieStore.getCookie(httpUrl);
showToast(httpUrl.host() + "对应的cookie如下:" + cookies.toString());
}
use of okhttp3.Cookie in project okhttp by square.
the class CookiesTest method testNetscapeResponse.
@Test
public void testNetscapeResponse() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
client = client.newBuilder().cookieJar(new JavaNetCookieJar(cookieManager)).build();
MockWebServer server = new MockWebServer();
server.start();
HttpUrl urlWithIpAddress = urlWithIpAddress(server, "/path/foo");
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "expires=Fri, 31-Dec-9999 23:59:59 GMT; " + "path=/path; " + "domain=" + urlWithIpAddress.host() + "; " + "secure"));
get(urlWithIpAddress);
List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
assertEquals(1, cookies.size());
HttpCookie cookie = cookies.get(0);
assertEquals("a", cookie.getName());
assertEquals("android", cookie.getValue());
assertEquals(null, cookie.getComment());
assertEquals(null, cookie.getCommentURL());
assertEquals(false, cookie.getDiscard());
assertTrue(cookie.getMaxAge() > 100000000000L);
assertEquals("/path", cookie.getPath());
assertEquals(true, cookie.getSecure());
assertEquals(0, cookie.getVersion());
}
use of okhttp3.Cookie in project okhttp by square.
the class CookiesTest method testRfc2109Response.
@Test
public void testRfc2109Response() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
client = client.newBuilder().cookieJar(new JavaNetCookieJar(cookieManager)).build();
MockWebServer server = new MockWebServer();
server.start();
HttpUrl urlWithIpAddress = urlWithIpAddress(server, "/path/foo");
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "Comment=this cookie is delicious; " + "Domain=" + urlWithIpAddress.host() + "; " + "Max-Age=60; " + "Path=/path; " + "Secure; " + "Version=1"));
get(urlWithIpAddress);
List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();
assertEquals(1, cookies.size());
HttpCookie cookie = cookies.get(0);
assertEquals("a", cookie.getName());
assertEquals("android", cookie.getValue());
assertEquals(null, cookie.getCommentURL());
assertEquals(false, cookie.getDiscard());
// Converting to a fixed date can cause rounding!
assertEquals(60.0, cookie.getMaxAge(), 1.0);
assertEquals("/path", cookie.getPath());
assertEquals(true, cookie.getSecure());
}
Aggregations