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


Java CookieStore.add方法代码示例

本文整理汇总了Java中java.net.CookieStore.add方法的典型用法代码示例。如果您正苦于以下问题:Java CookieStore.add方法的具体用法?Java CookieStore.add怎么用?Java CookieStore.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.CookieStore的用法示例。


在下文中一共展示了CookieStore.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldAddCookieToSharedPreferences

import java.net.CookieStore; //导入方法依赖的package包/类
@Test
public void shouldAddCookieToSharedPreferences() throws URISyntaxException {
    URI uri = URI.create("http://google.com");
    CookieStore store = new CookieTray(preferences);
    HttpCookie httpCookie = new HttpCookie("name", "value");
    store.add(uri, httpCookie);
    String cookieVal = new SerializableCookie(httpCookie).asString();
    verify(editor).putString(uri.toString() + "|" + httpCookie.getName(), cookieVal);
}
 
开发者ID:abohomol,项目名称:cookietray,代码行数:10,代码来源:CookieTrayTest.java

示例2: updateNetResponseCookies

import java.net.CookieStore; //导入方法依赖的package包/类
/**
 * write net cookies
 *
 * @param cookiesHeader
 */
private static void updateNetResponseCookies(List<String> cookiesHeader) {
    //write net cookie
    final CookieStore cookieStore = getCookieManager().getCookieStore();
    if (cookieStore != null && cookiesHeader != null) {
        HttpCookie cookieStr = null;
        for (String cookieHeader : cookiesHeader) {
            if (cookieHeader != null) {
                List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
                if (cookies != null && cookies.size() > 0) {
                    cookieStr = cookies.get(0);
                    LogUtil.d(TAG, "write-net", cookieStr);
                    cookieStore.add(null, cookieStr);
                }
            }
        }
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:23,代码来源:CookieManager.java

示例3: setAuthCookieVal

import java.net.CookieStore; //导入方法依赖的package包/类
protected void setAuthCookieVal(String authCookie, String domain) {
    this.authCookie = authCookie;
    settings.edit().putString(prefKey, authCookie).apply();

    /*
    this is technically unnecessary if OkHttp handled the authentication, because it will
    have already set the cookies in the CookieHandler. It doesn't seem to cause any issues
    just to re-add the cookies, though
     */
    HttpCookie httpCookie = new HttpCookie(authCookieKey, authCookie);
    httpCookie.setDomain(domain);
    try {
        CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
        cookies.add(URI.create(domain), httpCookie);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    cookieHasBeenSet = true;
    android.webkit.CookieManager.getInstance().setCookie(domain, httpCookie.getName() + "=" + httpCookie.getValue());
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        android.webkit.CookieManager.getInstance().flush();
    } else {
        CookieSyncManager.getInstance().sync();
    }
}
 
开发者ID:NasaGeek,项目名称:utexas-utilities,代码行数:26,代码来源:AuthCookie.java

示例4: getUinAndPsessionid

import java.net.CookieStore; //导入方法依赖的package包/类
private void getUinAndPsessionid()
		throws InterruptedException, ExecutionException, TimeoutException, URISyntaxException {
	LOGGER.debug("开始获取uin和psessionid");

	{
		CookieStore cookieStore = httpClient.getCookieStore();
		cookieStore.add(new URI("qq.com"), new HttpCookie("pgv_info", "ssid=s" + RandomUtil.numberString(10)));
		cookieStore.add(new URI("qq.com"), new HttpCookie("pgv_pvid", RandomUtil.numberString(10)));
		httpClient
				.newRequest(
						"https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=16&mibao_css=m_webqq&appid=501004106&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fw.qq.com%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001")
				.method(HttpMethod.GET).agent(ApiURL.USER_AGENT).header("Referer", "http://w.qq.com/")
				.header("Upgrade-Insecure-Requests", "1").send();
	}

	httpClient.newRequest("http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2").method(HttpMethod.GET)
			.agent(ApiURL.USER_AGENT).header("Referer", "http://w.qq.com/").header("Upgrade-Insecure-Requests", "1")
			.send();

	JsonObject r = new JsonObject();
	r.addProperty("ptwebqq", ptwebqq);
	r.addProperty("clientid", Client_ID);
	r.addProperty("psessionid", "");
	r.addProperty("status", "online");

	ContentResponse response = post(ApiURL.GET_UIN_AND_PSESSIONID, r);
	JsonObject result = getJsonObjectResult(response);
	this.psessionid = result.get("psessionid").getAsString();
	this.uin = result.get("uin").getAsLong();
	this.selfUserStatus = result.get("status").getAsString();
}
 
开发者ID:Xianguang-Zhou,项目名称:smartqq-client,代码行数:32,代码来源:SmartQQClient.java

示例5: readFrom

import java.net.CookieStore; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void readFrom(
        @NotNull CookieStore store,
        @NotNull InputStream stream
) throws IOException {
    HashMap<URI, List<SerializableHttpCookie>> cookieMap = null;

    ByteArrayInputStream is = new ByteArrayInputStream(IOUtils.toByteArray(stream));
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(is);
        Object object = ois.readObject();
        if (object instanceof HashMap) {
            cookieMap = (HashMap<URI, List<SerializableHttpCookie>>) object;
        }
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(ois);
    }

    if (cookieMap == null) return;

    for (URI uri : cookieMap.keySet()) {
        List<SerializableHttpCookie> cookies = cookieMap.get(uri);
        for (SerializableHttpCookie cookie : cookies) {
            store.add(uri, cookie.toHttpCookie());
        }
    }

}
 
开发者ID:emoji-gen,项目名称:bottler,代码行数:33,代码来源:CookieStoreUtils.java

示例6: checkCookieNullUri

import java.net.CookieStore; //导入方法依赖的package包/类
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    //Check if removeAll() retrurns false on an empty CookieStore
    if (cookieStore.removeAll()) {
        fail = true;
    }
    checkFail("removeAll on empty store should return false");
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:NullUriCookieTest.java

示例7: testStoredCookieRefTagForProject

import java.net.CookieStore; //导入方法依赖的package包/类
@Test
public void testStoredCookieRefTagForProject() {
  final CookieManager cookieManager = new CookieManager();
  final CookieStore cookieStore = cookieManager.getCookieStore();
  final Project project = ProjectFactory.project();
  final RefTag refTag = RefTag.recommended();

  // set the cookie and retrieve the ref tag
  cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
  final RefTag retrievedRefTag = RefTagUtils.storedCookieRefTagForProject(project, cookieManager, sharedPreferences);

  assertNotNull(retrievedRefTag);
  assertEquals(refTag, retrievedRefTag);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:15,代码来源:RefTagUtilsTest.java

示例8: testFindRefTagCookieForProject_WhenCookieExists

import java.net.CookieStore; //导入方法依赖的package包/类
@Test
public void testFindRefTagCookieForProject_WhenCookieExists() {
  final CookieManager cookieManager = new CookieManager();
  final CookieStore cookieStore = cookieManager.getCookieStore();
  final Project project = ProjectFactory.project();
  final RefTag refTag = RefTag.recommended();

  // set and retrieve the cookie
  cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
  final HttpCookie cookie = RefTagUtils.findRefTagCookieForProject(project, cookieManager, sharedPreferences);

  assertNotNull(cookie);
  assertEquals(RefTagUtils.cookieNameForProject(project), cookie.getName());
  assertEquals(RefTagUtils.cookieValueForRefTag(refTag), cookie.getValue());
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:16,代码来源:RefTagUtilsTest.java

示例9: setup

import java.net.CookieStore; //导入方法依赖的package包/类
public static synchronized boolean setup()
{
	Settings settings = DataStoreManager.getSettings();
	gmtOffset = settings.getGmtOffset();
	sugarUrl = settings.getCrmUrl();
	api = new SugarApi(sugarUrl);
	try
	{
		session = api.getSugarSession(new SugarCredentials(settings.getUser(), settings.getPassword()));

		String sessionId = session.getSessionID();
		
		CookieManager manager = new CookieManager();
	    manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
	    CookieStore store = manager.getCookieStore();
	    store.add(new URI(sugarUrl), new HttpCookie("PHPSESSID", sessionId));
	    CookieHandler.setDefault(manager);
	    
		
		return true;
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}

	return false;
}
 
开发者ID:tfreier,项目名称:desktop-crm,代码行数:29,代码来源:CrmManager.java

示例10: testCookieStoreRemoveAll

import java.net.CookieStore; //导入方法依赖的package包/类
public void testCookieStoreRemoveAll() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("http://code.google.com/"), new HttpCookie("a", "android"));
    assertTrue(cookieStore.removeAll());
    assertEquals(Collections.<URI>emptyList(), cookieStore.getURIs());
    assertEquals(Collections.<HttpCookie>emptyList(), cookieStore.getCookies());
    assertFalse("Expected removeAll() to return false when the call doesn't mutate the store",
            cookieStore.removeAll());  // RI6 fails this
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:10,代码来源:CookiesTest.java

示例11: testCookieStoreAddAcceptsConflictingUri

import java.net.CookieStore; //导入方法依赖的package包/类
public void testCookieStoreAddAcceptsConflictingUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieA.setDomain(".android.com");
    cookieA.setPath("/source/");
    cookieStore.add(new URI("http://google.com/source/"), cookieA);
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:9,代码来源:CookiesTest.java

示例12: testCookieStoreRemoveRequiresUri

import java.net.CookieStore; //导入方法依赖的package包/类
public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    HttpCookie cookieA = new HttpCookie("a", "android");
    cookieStore.add(new URI("http://android.com/source/"), cookieA);
    assertFalse("Expected remove() to take the cookie URI into account.", // RI6 fails this
            cookieStore.remove(new URI("http://code.google.com/"), cookieA));
    assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:9,代码来源:CookiesTest.java

示例13: checkCookieNullUri

import java.net.CookieStore; //导入方法依赖的package包/类
static void checkCookieNullUri() throws Exception {
    //get a cookie store implementation and add a cookie to the store with null URI
    CookieStore cookieStore = (new CookieManager()).getCookieStore();
    HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
    cookie.setDomain("foo.com");
    cookieStore.add(null, cookie);

    //Retrieve added cookie
    URI uri = new URI("http://foo.com");
    List<HttpCookie> addedCookieList = cookieStore.get(uri);

    //Verify CookieStore behaves well
    if (addedCookieList.size() != 1) {
       fail = true;
    }
    checkFail("Abnormal size of cookie jar");

    for (HttpCookie chip : addedCookieList) {
        if (!chip.equals(cookie)) {
             fail = true;
        }
    }
    checkFail("Cookie not retrieved from Cookie Jar");
    boolean ret = cookieStore.remove(null,cookie);
    if (!ret) {
        fail = true;
    }
    checkFail("Abnormal removal behaviour from Cookie Jar");
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:30,代码来源:NullUriCookieTest.java

示例14: testCookieStoreUriUsesHttpSchemeAlways

import java.net.CookieStore; //导入方法依赖的package包/类
public void testCookieStoreUriUsesHttpSchemeAlways() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("https://a.com/"), new HttpCookie("a", "android"));
    assertEquals(Arrays.asList(new URI("http://a.com")), cookieStore.getURIs());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:6,代码来源:CookiesTest.java

示例15: testCookieStoreUriDropsUserInfo

import java.net.CookieStore; //导入方法依赖的package包/类
public void testCookieStoreUriDropsUserInfo() throws URISyntaxException {
    CookieStore cookieStore = new CookieManager().getCookieStore();
    cookieStore.add(new URI("http://jesse:[email protected]/"), new HttpCookie("a", "android"));
    assertEquals(Arrays.asList(new URI("http://a.com")), cookieStore.getURIs());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:6,代码来源:CookiesTest.java


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