Search in sources :

Example 46 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project warn-report by saaavsaaa.

the class WebRequestClient method setCookie.

private static void setCookie(String loginToken, String loginUserID) {
    Cookie[] cookies = new Cookie[2];
    cookies[0] = new BasicClientCookie(LOGIN_USERTOKEN_KEY, loginToken);
    cookies[1] = new BasicClientCookie(LOGIN_USERID_KEY, loginUserID);
    setCookies(cookies);
/*		// 创建一个本地上下文信息
		HttpContext localContext = new BasicHttpContext();
		// 在本地上下问中绑定一个本地存储
		localContext.setAttribute(HttpClientContext.COOKIE_STORE, cs);
		cs.addCookie(new BasicClientCookie(LOGIN_USERTOKEN_KEY, loginToken));
		cs.addCookie(new BasicClientCookie(LOGIN_USERID_KEY, loginUserID));*/
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie)

Example 47 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project warn-report by saaavsaaa.

the class WebRequestClient method setCookies.

private static void setCookies(Map<String, String> cookieKVs) {
    Cookie[] cookies = new Cookie[cookieKVs.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : cookieKVs.entrySet()) {
        cookies[i] = new BasicClientCookie(entry.getKey(), entry.getValue());
        i++;
    }
    setCookies(cookies);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Map(java.util.Map)

Example 48 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project sling-org-apache-sling-testing-clients by apache.

the class SlingClient method impersonate.

/**
 * Impersonate user with the given <code>userId</code>
 * <p>
 * By impersonating a user SlingClient can access content from the perspective of that user.
 * </p>
 *Passing a <code>null</code> will clear impersonation.
 *
 * @param userId   the user to impersonate. A <code>null</code> value clears impersonation
 */
public SlingClient impersonate(String userId) {
    if (userId == null) {
        endImpersonation();
        return this;
    }
    BasicClientCookie c = new BasicClientCookie(getSudoCookieName(), userId);
    c.setPath("/");
    c.setDomain(getUrl().getHost());
    getCookieStore().addCookie(c);
    return this;
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie)

Example 49 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project sling-org-apache-sling-testing-clients by apache.

the class SlingClient method endImpersonation.

/**
 * End the impersonation of the current user.
 */
public SlingClient endImpersonation() {
    BasicClientCookie c = new BasicClientCookie(getSudoCookieName(), "");
    c.setPath("/");
    c.setDomain(getUrl().getHost());
    // setting expiry date in the past will remove the cookie
    c.setExpiryDate(new Date(0));
    getCookieStore().addCookie(c);
    return this;
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Date(java.util.Date)

Example 50 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project xUtils by wyouflf.

the class HttpFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.http_fragment, container, false);
    ViewUtils.inject(this, view);
    mAppContext = inflater.getContext().getApplicationContext();
    downloadManager = DownloadService.getDownloadManager(mAppContext);
    preferencesCookieStore = new PreferencesCookieStore(mAppContext);
    BasicClientCookie cookie = new BasicClientCookie("test", "hello");
    cookie.setDomain("192.168.1.5");
    cookie.setPath("/");
    preferencesCookieStore.addCookie(cookie);
    return view;
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) View(android.view.View) TextView(android.widget.TextView) PreferencesCookieStore(com.lidroid.xutils.util.PreferencesCookieStore)

Aggregations

BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)88 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)36 Test (org.junit.Test)24 HttpResponse (org.apache.http.HttpResponse)19 Cookie (org.apache.http.cookie.Cookie)17 HttpClient (org.apache.http.client.HttpClient)15 HttpGet (org.apache.http.client.methods.HttpGet)15 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)15 Map (java.util.Map)14 RequestConfig (org.apache.http.client.config.RequestConfig)13 HttpPost (org.apache.http.client.methods.HttpPost)9 CookieAttributeHandler (org.apache.http.cookie.CookieAttributeHandler)9 CookieOrigin (org.apache.http.cookie.CookieOrigin)9 URL (java.net.URL)8 HttpEntity (org.apache.http.HttpEntity)8 CookieStore (org.apache.http.client.CookieStore)8 IOException (java.io.IOException)7 Date (java.util.Date)7 ClientCookie (org.apache.http.cookie.ClientCookie)7 HashMap (java.util.HashMap)6