當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicClientCookie類代碼示例

本文整理匯總了Java中org.apache.http.impl.cookie.BasicClientCookie的典型用法代碼示例。如果您正苦於以下問題:Java BasicClientCookie類的具體用法?Java BasicClientCookie怎麽用?Java BasicClientCookie使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasicClientCookie類屬於org.apache.http.impl.cookie包,在下文中一共展示了BasicClientCookie類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createOkResponseWithCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
private Answer<HttpResponse> createOkResponseWithCookie() {
    return new Answer<HttpResponse>() {
        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpContext context = (HttpContext) invocation.getArguments()[1];
            if (context.getAttribute(ClientContext.COOKIE_STORE) != null) {
                BasicCookieStore cookieStore =
                        (BasicCookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
                BasicClientCookie cookie = new BasicClientCookie("cookie", "meLikeCookie");
                cookieStore.addCookie(cookie);
            }

            return OK_200_RESPONSE;
        }
    };
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:17,代碼來源:WebDavStoreTest.java

示例2: addCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的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.impl.cookie.BasicClientCookie; //導入依賴的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: getuCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
public static CookieStore getuCookie() {
    CookieStore uCookie = new BasicCookieStore();
    try {
        String COOKIE_S_LINKDATA = LemallPlatform.getInstance().getCookieLinkdata();
        if (!TextUtils.isEmpty(COOKIE_S_LINKDATA)) {
            String[] cookies = COOKIE_S_LINKDATA.split("&");
            for (String item : cookies) {
                String[] keyValue = item.split(SearchCriteria.EQ);
                if (keyValue.length == 2) {
                    if (OtherUtil.isContainsChinese(keyValue[1])) {
                        keyValue[1] = URLEncoder.encode(keyValue[1], "UTF-8");
                    }
                    BasicClientCookie cookie = new BasicClientCookie(keyValue[0], keyValue[1]);
                    cookie.setVersion(0);
                    cookie.setDomain(".lemall.com");
                    cookie.setPath("/");
                    uCookie.addCookie(cookie);
                }
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return uCookie;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:AsyncHttpClient.java

示例5: saveCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
private static void saveCookie(String url){
	String cookie = CookieManager.getInstance().getCookie(url);
	if(cookie !=null && !cookie.equals("")){  
           String[] cookies = cookie.split(";");  
           for(int i=0; i< cookies.length; i++){  
               String[] nvp = cookies[i].split("=");  
               BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]);  
               //c.setVersion(0);  
               c.setDomain("kyfw.12306.cn");
               MyCookieStore myCookieStore = null;
               if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore()
               		instanceof MyCookieStore){
               	myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore();
               }
               if (myCookieStore != null){
               	myCookieStore.addCookie(c);
               }
           }
      }  
	CookieSyncManager.getInstance().sync();
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:22,代碼來源:WebViewUtil.java

示例6: SaveCookies

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
public void SaveCookies(HttpResponse httpResponse) {
    Header[] headers = httpResponse.getHeaders("Set-Cookie");
    String headerstr = headers.toString();

    if (headers != null) {
        for (int i = 0; i < headers.length; i++) {

            String cookie = headers[i].getValue();
            String[] cookievalues = cookie.split(";");

            for (int j = 0; j < cookievalues.length; j++) {
                String[] keyPair = cookievalues[j].split("=");
                String key = keyPair[0].trim();
                String value = keyPair.length > 1 ? keyPair[1].trim() : "";
                BasicClientCookie newCookie = new BasicClientCookie(key, value);
                cookieStore.addCookie(newCookie);
            }
        }
    }
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:21,代碼來源:SyncHttpClient.java

示例7: loadCookies

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
private void loadCookies() throws IOException {

        CookieManager cm = getWebClient().getCookieManager();

        File cookiesFile = Directories.META.getDir("cookies.json");
        if (cookiesFile.exists()) {
            String content = HTMLUtil.readFile(cookiesFile);

            List<BasicClientCookie> list = new Gson().fromJson(content, new TypeToken<List<BasicClientCookie>>() {
            }.getType());

            for (BasicClientCookie bc : list) {
                Cookie c = new Cookie(bc.getDomain(), bc.getName(), bc.getValue());
                cm.addCookie(c);
            }
        }
    }
 
開發者ID:openaudible,項目名稱:openaudible,代碼行數:18,代碼來源:AudibleScraper.java

示例8: saveCookies

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
public void saveCookies() throws IOException {

        CookieManager cm = getWebClient().getCookieManager();
        ArrayList<BasicClientCookie> list = new ArrayList<>();

        for (Cookie c : cm.getCookies()) {
            BasicClientCookie bc = new BasicClientCookie(c.getName(), c.getValue());
            bc.setDomain(c.getDomain());
            bc.setPath(c.getPath());
            list.add(bc);
        }


        File cookiesFile = Directories.META.getDir("cookies.json");
        if (cookiesFile.exists()) {
            cookiesFile.delete();
        }

        String o = new Gson().toJson(list);
        FileUtils.writeByteArrayToFile(cookiesFile, o.getBytes());

    }
 
開發者ID:openaudible,項目名稱:openaudible,代碼行數:23,代碼來源:AudibleScraper.java

示例9: setCookieStore

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
public static void setCookieStore(HttpResponse httpResponse) {
  System.out.println("----setCookieStore");
  cookieStore = new BasicCookieStore();
  // JSESSIONID
  String setCookie = httpResponse.getFirstHeader("Set-Cookie")
      .getValue();
  String JSESSIONID = setCookie.substring("JSESSIONID=".length(),
      setCookie.indexOf(";"));
  System.out.println("JSESSIONID:" + JSESSIONID);
  // 新建一個Cookie
  BasicClientCookie cookie = new BasicClientCookie("JSESSIONID",
      JSESSIONID);
  cookie.setVersion(0);
  //cookie.setDomain("127.0.0.1");
  //cookie.setPath("/CwlProClient");
  // cookie.setAttribute(ClientCookie.VERSION_ATTR, "0");
  // cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "127.0.0.1");
  // cookie.setAttribute(ClientCookie.PORT_ATTR, "8080");
  // cookie.setAttribute(ClientCookie.PATH_ATTR, "/CwlProWeb");
  cookieStore.addCookie(cookie);
}
 
開發者ID:bluetata,項目名稱:crawler-jsoup-maven,代碼行數:22,代碼來源:CSDNLoginApater.java

示例10: authToGoogle

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
/**
 * Authentication with google account
 * @param cookies cookies list keys from google auth
 * @param login username associated to zds login
 * @param id user id on ZdS associated to login
 */
public void authToGoogle(List<HttpCookie> cookies, String login, String id) {
    if(login != null && id != null) {
        this.login = login;
        this.idUser = id;
        log.info("L'identifiant de l'utilisateur " + this.login + " est : " + idUser);
        cookieStore = new BasicCookieStore();
        for(HttpCookie cookie:cookies) {
            BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue());
            c.setDomain(cookie.getDomain());
            c.setPath(cookie.getPath());
            c.setSecure(cookie.getSecure());
            c.setVersion(cookie.getVersion());
            c.setComment(cookie.getComment());
            cookieStore.addCookie(c);
        }
        context.setCookieStore(cookieStore);
        this.authenticated = true;
    }
    else {
        log.debug("Le login de l'utilisateur n'a pas pu être trouvé");
    }
}
 
開發者ID:firm1,項目名稱:zest-writer,代碼行數:29,代碼來源:ZdsHttp.java

示例11: batchCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
/**
 * batchCookies
 * 
 * @param cookiestring
 *            the cookie string, eg.:"a=b;c=a"
 * @param domain
 *            the domain
 * @param path
 *            the path
 * @param expired
 *            the expired date
 */
public synchronized void batchCookie(String cookiestring, String domain, String path, Date expired) {
	String[] ss = X.split(cookiestring, ";");
	for (String s : ss) {
		StringFinder sf = StringFinder.create(s);
		String name = sf.nextTo("=");
		String value = sf.remain();
		if (!X.isEmpty(name)) {
			removeCookie(name, domain, path);

			BasicClientCookie c = new BasicClientCookie(name, value);
			c.setDomain(domain);
			c.setPath(X.isEmpty(path) ? "/" : path);
			c.setExpiryDate(expired);
			cookies.addCookie(c);
		}
	}
}
 
開發者ID:giiwa,項目名稱:giiwa,代碼行數:30,代碼來源:Http.java

示例12: setCookies

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
public void setCookies(Map<String, String> cookies, String domain, String path) {
    if (null == cookies || cookies.isEmpty()) {
        return;
    }

    for (String key : cookies.keySet()) {
        BasicClientCookie cookie = new BasicClientCookie(key, cookies.get(key));
        if (domain.startsWith(HTTP_PRO)) {
            domain = domain.substring(HTTP_PRO.length());
        }
        if (domain.startsWith(HTTPS_PRO)) {
            domain = domain.substring(HTTPS_PRO.length());
        }
        cookie.setDomain(domain);
        if (StringUtils.isBlank(path)) {
            cookie.setPath("/");
        } else {
            cookie.setPath(path);
        }
        cookieStore.addCookie(cookie);
    }
}
 
開發者ID:storezhang,項目名稱:utils,代碼行數:23,代碼來源:HttpClient.java

示例13: createCookieForHeaderElementTest

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
@Test
public void createCookieForHeaderElementTest() {
    String cookiePath = "/client/api";

    String paramName = "paramName1";
    String paramValue = "paramVale1";
    NameValuePair[] parameters = new NameValuePair[1];
    parameters[0] = new BasicNameValuePair(paramName, paramValue);

    String headerName = "headerElementName";
    String headerValue = "headerElementValue";
    HeaderElement headerElement = new BasicHeaderElement(headerName, headerValue, parameters);

    Mockito.doNothing().when(apacheCloudStackClient).configureDomainForCookie(Mockito.any(BasicClientCookie.class));

    BasicClientCookie cookieForHeaderElement = apacheCloudStackClient.createCookieForHeaderElement(headerElement);

    Assert.assertNotNull(cookieForHeaderElement);
    Assert.assertEquals(headerName, cookieForHeaderElement.getName());
    Assert.assertEquals(headerValue, cookieForHeaderElement.getValue());
    Assert.assertEquals(paramValue, cookieForHeaderElement.getAttribute(paramName));
    Assert.assertEquals(cookiePath, cookieForHeaderElement.getPath());

    Mockito.verify(apacheCloudStackClient).configureDomainForCookie(Mockito.eq(cookieForHeaderElement));
}
 
開發者ID:Autonomiccs,項目名稱:apache-cloudstack-java-client,代碼行數:26,代碼來源:ApacheCloudStackClientTest.java

示例14: makeCookie

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
/**
 * Create an HttpClient cookie from a JMeter cookie
 */
private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) {
    long exp = jmc.getExpiresMillis();
    BasicClientCookie ret = new BasicClientCookie(jmc.getName(),
            jmc.getValue());
    ret.setDomain(jmc.getDomain());
    ret.setPath(jmc.getPath());
    ret.setExpiryDate(exp > 0 ? new Date(exp) : null); // use null for no expiry
    ret.setSecure(jmc.getSecure());
    ret.setVersion(jmc.getVersion());
    if(jmc.isDomainSpecified()) {
        ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain());
    }
    if(jmc.isPathSpecified()) {
        ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath());
    }
    return ret;
}
 
開發者ID:johrstrom,項目名稱:cloud-meter,代碼行數:21,代碼來源:HC4CookieHandler.java

示例15: createContext

import org.apache.http.impl.cookie.BasicClientCookie; //導入依賴的package包/類
@Override
public BasicHttpContext createContext(final HttpHost targetHost) {

    final CookieStore cookieStore = new BasicCookieStore();

    final BasicClientCookie clientCookie =
            new BasicClientCookie(cookie.getName(), cookie.getValue());
    clientCookie.setDomain(targetHost.getHostName());
    clientCookie.setPath("/");
    cookieStore.addCookie(clientCookie);

    final BasicHttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);

    return context;
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:17,代碼來源:UseCookieConfigurator.java


注:本文中的org.apache.http.impl.cookie.BasicClientCookie類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。