本文整理匯總了Java中java.net.CookieStore類的典型用法代碼示例。如果您正苦於以下問題:Java CookieStore類的具體用法?Java CookieStore怎麽用?Java CookieStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CookieStore類屬於java.net包,在下文中一共展示了CookieStore類的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: updateWebkitResponseCookies
import java.net.CookieStore; //導入依賴的package包/類
/**
* @param cookiesHeader
*/
private static String updateWebkitResponseCookies(List<String> cookiesHeader, String requestUrl) {
//write webkit cookie
final CookieStore cookieStore = getCookieManager().getCookieStore();
if (cookieStore != null && cookiesHeader != null) {
StringBuffer cookie = new StringBuffer();
for (String cookieHeader : cookiesHeader) {
cookie.append(cookieHeader).append(";");
}
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
if (cookieManager != null && cookie.length() > 0) {
String cookieStr = cookie.toString();
LogUtil.d(TAG, "write-webkit", cookieStr);
cookieManager.setCookie(requestUrl, cookieStr);
}
}
return null;
}
示例3: 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);
}
}
}
}
}
示例4: findRefTagCookieForProject
import java.net.CookieStore; //導入依賴的package包/類
/**
* Finds the ref tag cookie associated with a project. Returns `null` if no cookie has yet been set.
*/
protected static @Nullable HttpCookie findRefTagCookieForProject(final @NonNull Project project,
final @NonNull CookieManager cookieManager, final @NonNull SharedPreferences sharedPreferences) {
final String cookieName = cookieNameForProject(project);
// First try finding the cookie in the cookie store
final CookieStore cookieStore = cookieManager.getCookieStore();
for (final HttpCookie cookie : cookieStore.getCookies()) {
if (cookieName.equals(cookie.getName())) {
return cookie;
}
}
// If we can't find it in the cookie store let's look in shared prefs
final String cookieValue = sharedPreferences.getString(cookieName, null);
if (cookieValue != null) {
return buildCookieWithValueAndProject(cookieValue, project);
}
return null;
}
示例5: syncWebViewCookies
import java.net.CookieStore; //導入依賴的package包/類
public static void syncWebViewCookies(@NonNull Context context, @NonNull CookieStore cookieStore) {
CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
cookieManager.removeAllCookie();
List<URI> urls = cookieStore.getURIs();
for (URI url : urls) {
List<HttpCookie> cookies = cookieStore.get(url);
for (HttpCookie cookie : cookies) {
cookieManager.setCookie(url.toString(), cookie.toString());
}
L.w("Cookies", cookieManager.getCookie(url.toString()));
}
CookieSyncManager.getInstance().sync();
}
示例6: clearAuthorizationData
import java.net.CookieStore; //導入依賴的package包/類
/**
* Clear the local stored authorization data
*/
public void clearAuthorizationData() {
preferences.accessToken.clear();
preferences.idToken.clear();
preferences.userIdentity.clear();
if (BMSClient.getInstance() != null && BMSClient.getInstance().getCookieManager() != null) {
CookieStore cookieStore = BMSClient.getInstance().getCookieManager().getCookieStore();
if(cookieStore != null) {
for (URI uri : cookieStore.getURIs()) {
for (HttpCookie cookie : cookieStore.get(uri)) {
if (cookie.getName().equals(TAI_COOKIE_NAME)) {
cookieStore.remove(uri, cookie);
}
}
}
}
}
}
開發者ID:ibm-bluemix-mobile-services,項目名稱:bms-clientsdk-android-core,代碼行數:21,代碼來源:MCAAuthorizationManager.java
示例7: resetCookie
import java.net.CookieStore; //導入依賴的package包/類
private void resetCookie() {
settings.edit().remove(prefKey).apply();
authCookie = "";
try {
/*
This step is *required* for PNA, and nicety for other services. PNA won't let you
log in if you're still holding on to a valid authcookie, so we clear them out.
*/
URI loginURI = URI.create(url.getHost());
CookieStore cookies = ((CookieManager) CookieHandler.getDefault()).getCookieStore();
for (HttpCookie cookie : cookies.get(loginURI)) {
cookies.remove(loginURI, cookie);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
cookieHasBeenSet = false;
}
示例8: 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();
}
}
示例9: shouldBeAbleToRemoveCookie
import java.net.CookieStore; //導入依賴的package包/類
@Test
public void shouldBeAbleToRemoveCookie() {
addCookies(1, false);
CookieStore store = new CookieTray(preferences);
store.remove(URI.create("http://google.com/home0"), new HttpCookie("name0", "value0"));
verify(editor).remove("http://google.com/home0|name0");
}
示例10: shouldBeAbleToRemoveAllCookies
import java.net.CookieStore; //導入依賴的package包/類
@Test
public void shouldBeAbleToRemoveAllCookies() {
doReturn(editor).when(editor).clear();
CookieStore store = new CookieTray(preferences);
store.removeAll();
verify(editor).clear();
assertTrue("No cookies should be present after removing", store.getCookies().isEmpty());
}
示例11: clearNetCookies
import java.net.CookieStore; //導入依賴的package包/類
/**
* clear net cookies
*/
public static void clearNetCookies() {
java.net.CookieManager cookieManager = getCookieManager();
CookieStore cookieStore = cookieManager.getCookieStore();
if (cookieStore != null) {
cookieStore.removeAll();
}
}
示例12: getNetRequestCookies
import java.net.CookieStore; //導入依賴的package包/類
/**
* net cookies
*/
private static String getNetRequestCookies() {
final CookieStore cookieStore = getCookieManager().getCookieStore();
//net cookie
if (cookieStore != null) {
final List<HttpCookie> cookies = cookieStore.getCookies();
if (cookies != null && cookies.size() > 0) {
//While joining the Cookies, use ',' or ';' as needed. Most of the server are using ';'
final String netCookie = TextUtils.join(";", cookies);
LogUtil.d(TAG, "get-net", netCookie);
return netCookie;
}
}
return null;
}
示例13: 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();
}
示例14: writeTo
import java.net.CookieStore; //導入依賴的package包/類
public static void writeTo(
@NotNull CookieStore store,
@NotNull OutputStream stream
) throws IOException {
HashMap<URI, List<SerializableHttpCookie>> cookieMap =
new HashMap<URI, List<SerializableHttpCookie>>();
List<URI> uris = store.getURIs();
for (URI uri : uris) {
List<HttpCookie> cookies = store.get(uri);
List<SerializableHttpCookie> serializableHttpCookies =
new ArrayList<SerializableHttpCookie>(cookies.size());
for (HttpCookie cookie : cookies) {
serializableHttpCookies.add(SerializableHttpCookie.of(cookie));
}
cookieMap.put(uri, serializableHttpCookies);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(os);
oos.writeObject(cookieMap);
oos.flush();
stream.write(os.toByteArray());
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(oos);
}
}
示例15: 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());
}
}
}