当前位置: 首页>>代码示例>>Java>>正文


Java CookieStore.getCookies方法代码示例

本文整理汇总了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()]);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:29,代码来源:FetchingThread.java

示例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());
}
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:17,代码来源:ClanBaseUtils.java

示例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;
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:19,代码来源:BaseParser.java

示例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;
}
 
开发者ID:bertrandmartel,项目名称:bboxapi-voicemail,代码行数:15,代码来源:ApiUtils.java

示例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();
	}
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:34,代码来源:AsyncClientCustomContext.java

示例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;
}
 
开发者ID:firm1,项目名称:zest-writer,代码行数:11,代码来源:ZdsHttp.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:11,代码来源:DcosAuthImpl.java

示例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;
}
 
开发者ID:dounine,项目名称:clouddisk,代码行数:11,代码来源:CookieStoreUT.java

示例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;
}
 
开发者ID:hazelcast,项目名称:hazelcast-wm,代码行数:8,代码来源:AbstractWebFilterTest.java

示例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();
}
 
开发者ID:libit,项目名称:lr_dialer,代码行数:17,代码来源:AjaxStatus.java

示例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();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:32,代码来源:ClientCustomContext.java

示例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();        
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:43,代码来源:ClientCustomContext.java

示例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;
    }
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:7,代码来源:CookieUtils.java


注:本文中的org.apache.http.client.CookieStore.getCookies方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。