本文整理汇总了Java中org.apache.http.client.CookieStore.getCookies方法的典型用法代码示例。如果您正苦于以下问题:Java CookieStore.getCookies方法的具体用法?Java CookieStore.getCookies怎么用?Java CookieStore.getCookies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.CookieStore
的用法示例。
在下文中一共展示了CookieStore.getCookies方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCookies
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
/** Returns the list of cookies in a given store in the form of an array, limiting their overall size
* (only the maximal prefix of cookies satisfying the size limit is returned). Note that the size limit is expressed
* in bytes, but the actual memory footprint is larger because of object overheads and because strings
* are made of 16-bits characters. Moreover, cookie attributes are not measured when evaluating size.
*
* @param url the URL which generated the cookies (for logging purposes).
* @param cookieStore a cookie store, usually generated by a response.
* @param cookieMaxByteSize the maximum overall size of cookies in bytes.
* @return the list of cookies in a given store in the form of an array, with limited overall size.
*/
public static Cookie[] getCookies(final URI url, final CookieStore cookieStore, final int cookieMaxByteSize) {
int overallLength = 0, i = 0;
final List<Cookie> cookies = cookieStore.getCookies();
for (Cookie cookie : cookies) {
/* Just an approximation, and doesn't take attributes into account, but
* there is no way to enumerate the attributes of a cookie. */
overallLength += length(cookie.getName());
overallLength += length(cookie.getValue());
overallLength += length(cookie.getDomain());
overallLength += length(cookie.getPath());
if (overallLength > cookieMaxByteSize) {
LOGGER.warn("URL " + url + " returned too large cookies (" + overallLength + " characters)");
return cookies.subList(0, i).toArray(new Cookie[i]);
}
i++;
}
return cookies.toArray(new Cookie[cookies.size()]);
}
示例2: printCookieStore
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public static void printCookieStore(CookieStore cookieStore) {
List<Cookie> cookies = cookieStore.getCookies();
Log.e("APP", "========================================== start cookies.size:" + cookies.size());
if (!cookies.isEmpty()) {
for (int i = 0; i < cookies.size(); i++) {
Cookie ck = cookies.get(i);
String ckstr = ck.getName() + "=" + ck.getValue() + ";"
+ "expiry=" + ck.getExpiryDate() + ";"
+ "domain=" + ck.getDomain() + ";"
+ "path=/";
Log.v("APP", "cookieStr:" + ckstr);
}
}
Log.e("APP", "========================================== end cookies.size:" + cookies.size());
}
示例3: readCookieStoreValue
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public String readCookieStoreValue(final String name) {
if (StringUtils.isBlank(name)) {
throw new CloudDiskException("cookie名称不能为空");
}
final CookieStore cookieStore = httpClientContext.getCookieStore();
final List<Cookie> cookies = cookieStore.getCookies();
Cookie cookie = null;
for (final Cookie coo : cookies) {
if (coo.getName().equals(name)) {
cookie = coo;
break;
}
}
if (null != cookie) {
return cookie.getValue();
}
return null;
}
示例4: hasSessionCookie
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
/**
* Check if PHPSESSID cookie is set.
*
* @param cookieStore
* @return true if session cookie is set.
*/
public static boolean hasSessionCookie(CookieStore cookieStore) {
for (Cookie cookie : cookieStore.getCookies()) {
if (cookie.getName().equalsIgnoreCase("PHPSESSID")) {
return true;
}
}
return false;
}
示例5: main
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
try {
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpClientContext localContext = HttpClientContext.create();
// Bind custom cookie store to the local context
localContext.setCookieStore(cookieStore);
HttpGet httpget = new HttpGet("http://localhost/");
System.out.println("Executing request " + httpget.getRequestLine());
httpclient.start();
// Pass local context as a parameter
Future<HttpResponse> future = httpclient.execute(httpget, localContext, null);
// Please note that it may be unsafe to access HttpContext instance
// while the request is still being executed
HttpResponse response = future.get();
System.out.println("Response: " + response.getStatusLine());
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Local cookie: " + cookies.get(i));
}
System.out.println("Shutting down");
} finally {
httpclient.close();
}
}
示例6: getCookieValue
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
private String getCookieValue(CookieStore cookieStore, String cookieName) {
String value = null;
for (Cookie cookie : cookieStore.getCookies()) {
if (cookie.getName().equals(cookieName)) {
value = cookie.getValue();
}
}
return value;
}
示例7: getTokenFromCookie
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
private String getTokenFromCookie(final HttpClientContext context) {
final CookieStore cookieStore = context.getCookieStore();
final List<Cookie> cookies = cookieStore.getCookies();
for (final Cookie c : cookies) {
if (c.getName().equals(DCOS_AUTH_COOKIE)) return c.getValue();
}
return null;
}
示例8: readCookieValueForDisk
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public String readCookieValueForDisk(final String filter) {
final CookieStore cookieStore = readCookieStoreForDisk(new String[] { filter });
final List<Cookie> cookies = cookieStore.getCookies();
for (final Cookie cookie : cookies) {
if (cookie.getName().equals(filter)) {
return cookie.getValue();
}
}
return null;
}
示例9: getHazelcastSessionId
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
String getHazelcastSessionId(CookieStore cookieStore) {
for (Cookie cookie : cookieStore.getCookies()) {
String name = cookie.getName();
if ("hazelcast.sessionId".equals(name)) return cookie.getValue();
}
return null;
}
示例10: getCookies
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
/**
* Return the cookies set by the server.
* <p/>
* Return values only when source is not from cache (source == NETWORK), returns empty list otherwise.
*
* @return cookies
*/
public List<Cookie> getCookies()
{
if (context == null)
return Collections.emptyList();
CookieStore store = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
if (store == null)
return Collections.emptyList();
return store.getCookies();
}
示例11: main
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpClientContext localContext = HttpClientContext.create();
// Bind custom cookie store to the local context
localContext.setCookieStore(cookieStore);
HttpGet httpget = new HttpGet("http://httpbin.org/cookies");
System.out.println("Executing request " + httpget.getRequestLine());
// Pass local context as a parameter
CloseableHttpResponse response = httpclient.execute(httpget, localContext);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Local cookie: " + cookies.get(i));
}
EntityUtils.consume(response.getEntity());
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
示例12: main
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public final static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
List<Cookie> cookies = cookieStore.getCookies();
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Local cookie: " + cookies.get(i));
}
// Consume response content
if (entity != null) {
entity.consumeContent();
}
System.out.println("----------------------------------------");
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
示例13: getCookies
import org.apache.http.client.CookieStore; //导入方法依赖的package包/类
public static List<Cookie> getCookies(Context context) {
CookieStore cookieStore = com.youzu.clan.base.net.CookieManager.getInstance().getCookieStore(context);
List<Cookie> cookies = cookieStore.getCookies();
return cookies;
}