本文整理匯總了Java中org.apache.http.impl.client.BasicCookieStore.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicCookieStore.clear方法的具體用法?Java BasicCookieStore.clear怎麽用?Java BasicCookieStore.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.client.BasicCookieStore
的用法示例。
在下文中一共展示了BasicCookieStore.clear方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: removeCookie
import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
/**
* Remove a Cookie by name and path
*
* @param name cookie name
* @param path cookie path
*/
@PublicAtsApi
public void removeCookie( String name, String path ) {
BasicCookieStore cookieStore = (BasicCookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
if (cookieStore != null) {
List<Cookie> cookies = cookieStore.getCookies();
cookieStore.clear();
for (Cookie cookie : cookies) {
if (!cookie.getName().equals(name) || !cookie.getPath().equals(path)) {
cookieStore.addCookie(cookie);
}
}
}
}
示例2: clearCookies
import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
/**
* Clear all cookies
*/
@PublicAtsApi
public void clearCookies() {
BasicCookieStore cookieStore = (BasicCookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
if (cookieStore != null) {
cookieStore.clear();
}
}
示例3: testSyncWithCookies
import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
@Test
public void testSyncWithCookies() throws IOException, NoSuchAlgorithmException, IllegalArgumentException {
final URI url0 = BURL.parse(new MutableString("http://foo.bar/goo/first.html"));
final URI url1 = BURL.parse(new MutableString("http://foo.bar/goo/second.html"));
final String content0 = "";
final String content1 = "";
proxy = new SimpleFixedHttpProxy(true);
proxy.add200(url0, "Set-cookie: cookie=hello; Domain: foo.bar", content0);
proxy.add200(url1, "", content1);
proxy.start();
FetchData fetchData = new FetchData(testConfiguration);
BasicCookieStore cookieStore = new BasicCookieStore();
HttpClient httpClient = getHttpClient(new HttpHost("localhost", proxy.port()), false, cookieStore);
// This shows we do receive cookies
fetchData.fetch(url0, httpClient, null, null, false);
Cookie[] cookie = FetchingThread.getCookies(url0, cookieStore, testConfiguration.cookieMaxByteSize);
assertEquals("cookie", cookie[0].getName());
assertEquals("hello", cookie[0].getValue());
// This shows we do send cookies
// First attempt: sending back the same cookies just received
fetchData.fetch(url1, httpClient, null, null, false);
assertTrue(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("hello"));
// Second attempt: sending new cookies
cookieStore.clear();
BasicClientCookie clientCookie = new BasicClientCookie("returned", "cookie");
clientCookie.setDomain("foo.bar");
cookieStore.addCookie(clientCookie);
fetchData.fetch(url1, httpClient, null, null, false);
assertTrue(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("returned"));
// This shows we do not send undue cookies
cookieStore.clear();
clientCookie.setDomain("another.domain");
cookieStore.addCookie(clientCookie);
fetchData.fetch(url1, httpClient, null, null, false);
assertFalse(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("returned"));
System.out.println(Arrays.toString(FetchingThread.getCookies(url1, cookieStore, testConfiguration.cookieMaxByteSize)));
fetchData.close();
}