本文整理匯總了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);
}
示例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);
}
}
}
}
}
示例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();
}
}
示例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();
}
示例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());
}
}
}
示例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");
}
示例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);
}
示例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());
}
示例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;
}
示例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
}
示例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());
}
示例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());
}
示例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");
}
示例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());
}
示例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());
}