cz.msebera.android.httpclient.impl.cookie.BasicClientCookie Java Examples

The following examples show how to use cz.msebera.android.httpclient.impl.cookie.BasicClientCookie. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Cookie.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new cookie with the specified name and value which applies to the specified domain,
 * the specified path, and expires on the specified date.
 * @param domain the domain to which this cookie applies
 * @param name the cookie name
 * @param value the cookie name
 * @param path the path to which this cookie applies
 * @param expires the date on which this cookie expires
 * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP)
 * @param httpOnly whether or not this cookie should be only used for HTTP(S) headers
 */
public Cookie(final String domain, final String name, final String value, final String path, final Date expires,
    final boolean secure, final boolean httpOnly) {
    if (domain == null) {
        throw new IllegalArgumentException("Cookie domain must be specified");
    }

    final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : "");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setExpiryDate(expires);
    cookie.setSecure(secure);
    if (httpOnly) {
        cookie.setAttribute("httponly", "true");
    }
    httpClientCookie_ = cookie;
}
 
Example #2
Source File: Cookie.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new cookie with the specified name and value which applies to the specified domain,
 * the specified path, and expires after the specified amount of time.
 * @param domain the domain to which this cookie applies
 * @param name the cookie name
 * @param value the cookie name
 * @param path the path to which this cookie applies
 * @param maxAge the number of seconds for which this cookie is valid; <tt>-1</tt> indicates that the
 *        cookie should never expire; other negative numbers are not allowed
 * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP)
 */
public Cookie(final String domain, final String name, final String value, final String path, final int maxAge,
    final boolean secure) {

    final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : "");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setSecure(secure);

    if (maxAge < -1) {
        throw new IllegalArgumentException("invalid max age:  " + maxAge);
    }
    if (maxAge >= 0) {
        cookie.setExpiryDate(new Date(System.currentTimeMillis() + (maxAge * 1000)));
    }

    httpClientCookie_ = cookie;
}
 
Example #3
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP GET request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
 
Example #4
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void postUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example #5
Source File: CloudflareChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initHttpClient() {
    if (canCloudflare()) {
        String cloudflareCookieValue = preferences.getString(getSharedKey(PREF_KEY_CLOUDFLARE_COOKIE_VALUE), null);
        String cloudflareCookieDomain = getCloudflareCookieDomain();
        if (cloudflareCookieValue != null && cloudflareCookieDomain != null) {
            BasicClientCookie c = new BasicClientCookie(CLOUDFLARE_COOKIE_NAME, cloudflareCookieValue);
            c.setDomain(cloudflareCookieDomain);
            httpClient.getCookieStore().addCookie(c);
        }
    }
}
 
Example #6
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void loadHanabiraCookie() {
    String hanabiraCookie = preferences.getString(getSharedKey(PREF_KEY_HANABIRA_COOKIE), null);
    if (hanabiraCookie != null) {
        BasicClientCookie c = new BasicClientCookie(HANABIRA_COOKIE_NAME, hanabiraCookie);
        c.setDomain(getDomain());
        httpClient.getCookieStore().addCookie(c);
    }
}
 
Example #7
Source File: KrautModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void setKompturcodeCookie(String kompturcodeCookie) {
    if (kompturcodeCookie != null && kompturcodeCookie.length() > 0) {
        BasicClientCookie c = new BasicClientCookie(KOMTURCODE_COOKIE_NAME, kompturcodeCookie);
        c.setDomain(CHAN_DOMAIN);
        httpClient.getCookieStore().addCookie(c);
    }
}
 
Example #8
Source File: Chan410Module.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initHttpClient() {
    JSONObject savedCookies = new JSONObject(preferences.getString(getSharedKey(PREF_KEY_FAPTCHA_COOKIES), "{}"));
    for (String board : Chan410Boards.ALL_BOARDS_SET) {
        String value = savedCookies.optString(board);
        if (value != null && value.length() > 0) {
            BasicClientCookie c = new BasicClientCookie(board, value);
            c.setDomain("." + CHAN410_DOMAIN);
            c.setPath("/");
            httpClient.getCookieStore().addCookie(c);
        }
    }
}
 
Example #9
Source File: MikubaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initHttpClient() {
    super.initHttpClient();
    String sessionCookie = preferences.getString(getSharedKey(PREF_KEY_SESSION_COOKIE), null);
    if (sessionCookie != null) {
        BasicClientCookie c = new BasicClientCookie(SESSION_COOKIE_NAME, sessionCookie);
        c.setDomain(MIKUBA_DOMAIN);
        httpClient.getCookieStore().addCookie(c);
    }
}
 
Example #10
Source File: PonyachModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void loadPhpCookies(String usingDomain) {
    String phpSessionCookie = preferences.getString(getSharedKey(PREF_KEY_PHPSESSION_COOKIE), null);
    if (phpSessionCookie != null) {
        BasicClientCookie c = new BasicClientCookie(PHPSESSION_COOKIE_NAME, phpSessionCookie);
        c.setDomain(usingDomain);
        httpClient.getCookieStore().addCookie(c);
    }
}
 
Example #11
Source File: PonyachModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void setCaptchaTypeCookie() {
    PonyachModule thisModule = ((PonyachModule) MainApplication.getInstance().getChanModule(CHAN_NAME));
    String level = thisModule.preferences.getString(thisModule.getSharedKey(PREF_KEY_CAPTCHA_LEVEL), "1");
    BasicClientCookie cookie = new BasicClientCookie(CAPTCHATYPE_COOKIE_NAME, level);
    cookie.setDomain(thisModule.getUsingDomain());
    thisModule.httpClient.getCookieStore().addCookie(cookie);
}
 
Example #12
Source File: MakabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/** Установить cookie к текущему клиенту */
private void setCookie(String domain, String name, String value) {
    if (value == null || value.equals("")) return;
    BasicClientCookie c = new BasicClientCookie(name, value);
    c.setDomain(domain == null || domain.equals("") ? ("." + this.domain) : domain);
    c.setPath("/");
    httpClient.getCookieStore().addCookie(c);
}
 
Example #13
Source File: HtmlUnitHttpOnlyHandler.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
@Override
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException {
    ((BasicClientCookie) cookie).setAttribute(HTTPONLY_ATTR, "true");
}