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


Java Cookie类代码示例

本文整理汇总了Java中org.apache.http.cookie.Cookie的典型用法代码示例。如果您正苦于以下问题:Java Cookie类的具体用法?Java Cookie怎么用?Java Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: HttpResult

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public HttpResult(HttpResponse httpResponse, CookieStore cookieStore) {
	if (cookieStore != null) {
		this.cookies = cookieStore.getCookies().toArray(new Cookie[0]);
	}

	if (httpResponse != null) {
		this.headers = httpResponse.getAllHeaders();
		this.statuCode = httpResponse.getStatusLine().getStatusCode();
		if(d)System.out.println(this.statuCode);
		try {
			this.response = EntityUtils.toByteArray(httpResponse
					.getEntity());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:19,代码来源:HttpResult.java

示例2: addCookie

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
/**
 * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies.
 * If the given cookie has already expired it will not be added, but existing
 * values will still be removed.
 *
 * @param cookie the {@link Cookie cookie} to be added
 * @see #addCookies(Cookie[])
 */
@Override
public synchronized void addCookie(final Cookie cookie) {
    if (cookie != null) {
        // first remove any old cookie that is equivalent
        cookies.remove(cookie);
        Date now = new Date();
        if (!cookie.isExpired(now)) {
            Date targetExpiryDate = new Date(System.currentTimeMillis() + maxExpiresMillis);
            if (!cookie.isExpired(targetExpiryDate)) {
                try {
                    if (cookie instanceof BasicClientCookie) {
                        ((BasicClientCookie) cookie).setExpiryDate(targetExpiryDate);
                    } else if (cookie instanceof BasicClientCookie2) {
                        ((BasicClientCookie2) cookie).setExpiryDate(targetExpiryDate);
                    }
                } catch (Exception e) {
                }
            }

            cookies.add(cookie);
        }
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:32,代码来源:BarrierCookieStore.java

示例3: buildCookie

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
@Override
protected void buildCookie(com.intuit.karate.http.Cookie c) {
    BasicClientCookie cookie = new BasicClientCookie(c.getName(), c.getValue());
    for (Entry<String, String> entry : c.entrySet()) {
        switch (entry.getKey()) {
            case DOMAIN:
                cookie.setDomain(entry.getValue());
                break;
            case PATH:
                cookie.setPath(entry.getValue());
                break;
        }
    }
    if (cookie.getDomain() == null) {
        cookie.setDomain(uriBuilder.getHost());
    }
    cookieStore.addCookie(cookie);
}
 
开发者ID:intuit,项目名称:karate,代码行数:19,代码来源:ApacheHttpClient.java

示例4: PersistentCookieStore

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public PersistentCookieStore(Context context) {
    int i = 0;
    this.cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
    String storedCookieNames = this.cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        int length = cookieNames.length;
        while (i < length) {
            String name = cookieNames[i];
            String encodedCookie = this.cookiePrefs.getString(new StringBuilder(COOKIE_NAME_PREFIX).append(name).toString(), null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    this.cookies.put(name, decodedCookie);
                }
            }
            i++;
        }
        clearExpired(new Date());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:PersistentCookieStore.java

示例5: clearExpired

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    Editor prefsWriter = this.cookiePrefs.edit();
    for (Entry<String, Cookie> entry : this.cookies.entrySet()) {
        String name = (String) entry.getKey();
        if (((Cookie) entry.getValue()).isExpired(date)) {
            this.cookies.remove(name);
            prefsWriter.remove(new StringBuilder(COOKIE_NAME_PREFIX).append(name).toString());
            clearedAny = true;
        }
    }
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    }
    prefsWriter.commit();
    return clearedAny;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:PersistentCookieStore.java

示例6: clearExpired

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.apply();

    return clearedAny;
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:29,代码来源:PersistentCookieStore.java

示例7: clearExpired

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    Editor prefsWriter = this.cookiePrefs.edit();
    for (Entry<String, Cookie> entry : this.cookies.entrySet()) {
        String name = (String) entry.getKey();
        if (((Cookie) entry.getValue()).isExpired(date)) {
            this.cookies.remove(name);
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);
            clearedAny = true;
        }
    }
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    }
    prefsWriter.commit();
    return clearedAny;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:PersistentCookieStore.java

示例8: saveCookie

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public void saveCookie(Cookie cookie) {
	L.d("saveCookie:" + cookie);
	if (cookie == null) {
		return;
	}
	db.delete(TABLE_NAME, Column.NAME + " = ? ",
			new String[] { cookie.getName() });
	ContentValues values = new ContentValues();
	values.put(Column.VALUE, cookie.getValue());
	values.put(Column.NAME, cookie.getName());
	values.put(Column.COMMENT, cookie.getComment());
	values.put(Column.DOMAIN, cookie.getDomain());
	if (cookie.getExpiryDate() != null) {
		values.put(Column.EXPIRY_DATE, cookie.getExpiryDate().getTime());
	}
	values.put(Column.PATH, cookie.getPath());
	values.put(Column.SECURE, cookie.isSecure() ? 1 : 0);
	values.put(Column.VERSION, cookie.getVersion());

	db.insert(TABLE_NAME, null, values);
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:22,代码来源:MyCookieDBManager.java

示例9: PersistentCookieStore

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public PersistentCookieStore(Context context) {
    int i = 0;
    this.cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
    this.cookies = new ConcurrentHashMap();
    String storedCookieNames = this.cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
        String[] cookieNames = TextUtils.split(storedCookieNames, ",");
        int length = cookieNames.length;
        while (i < length) {
            String name = cookieNames[i];
            String encodedCookie = this.cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
            if (encodedCookie != null) {
                Cookie decodedCookie = decodeCookie(encodedCookie);
                if (decodedCookie != null) {
                    this.cookies.put(name, decodedCookie);
                }
            }
            i++;
        }
        clearExpired(new Date());
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:PersistentCookieStore.java

示例10: saveCookies

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public void saveCookies(List<Cookie> cookies){
	String strCookie = "";
       Date sessionTime = null;
       
       if (cookies != null && !cookies.isEmpty()) {
           for (int i = 0; i < cookies.size(); i++) {
           	Cookie cookie = cookies.get(i);
           	if (cookie.getName().equalsIgnoreCase("JSESSIONID")){
            	strCookie += cookie.getName() + "="
	                     + cookie.getValue() + ";domain="
	                     +cookie.getDomain();
	            sessionTime = cookies.get(i).getExpiryDate();
           	}
           }
       }
       editor.putString("cookies", strCookie);
	editor.commit();
	editor.putString("cookiesExpiryDate", (sessionTime == null)?null:TimeUtil.getDTFormat().format(sessionTime));
	editor.commit();
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:21,代码来源:A6UserInfoSPUtil.java

示例11: afterPropertiesSet

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider> create().register("easy", new CookieSpecProvider() {
		public CookieSpec create(HttpContext context) {
			return new DefaultCookieSpec() {
				@Override
				public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
				}
			};
		}
	}).build();

	requestConfig = RequestConfig.custom().setCookieSpec("easy")
			.setConnectionRequestTimeout(propertyConfigurer.getIntValue("connection.request.timeout"))
			.setSocketTimeout(propertyConfigurer.getIntValue("socket_timeout"))
			.setConnectTimeout(propertyConfigurer.getIntValue("connection_timeout")).build();
}
 
开发者ID:JK-River,项目名称:RobotServer,代码行数:18,代码来源:HttpService.java

示例12: addCookie

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
@Override
public void addCookie(Cookie cookie) {
    if (omitNonPersistentCookies && !cookie.isPersistent())
        return;
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:20,代码来源:PersistentCookieStore.java

示例13: parse

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
@Override
public List<Cookie> parse(
        final Header header,
        CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:RFC2965Spec.java

示例14: match

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (cookie.getVersion() > 0) {
        if (cookie instanceof SetCookie2) {
            return getStrict().match(cookie, origin);
        } else {
            return getObsoleteStrict().match(cookie, origin);
        }
    } else {
        return getCompat().match(cookie, origin);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BestMatchSpec.java

示例15: validate

import org.apache.http.cookie.Cookie; //导入依赖的package包/类
/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (!portMatch(port, cookie.getPorts())) {
            throw new CookieRestrictionViolationException(
                    "Port attribute violates RFC 2965: "
                    + "Request port not found in cookie's port list.");
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RFC2965PortAttributeHandler.java


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