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


Java BasicCookieStore.addCookie方法代碼示例

本文整理匯總了Java中org.apache.http.impl.client.BasicCookieStore.addCookie方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicCookieStore.addCookie方法的具體用法?Java BasicCookieStore.addCookie怎麽用?Java BasicCookieStore.addCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.client.BasicCookieStore的用法示例。


在下文中一共展示了BasicCookieStore.addCookie方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createOkResponseWithCookie

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的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: setCookieStore

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的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

示例3: authToGoogle

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的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

示例4: grabKey

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
@Ignore
public void grabKey() throws Exception {
    BasicCookieStore store = new BasicCookieStore();
    HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(store).build();
    store.addCookie(new BCookie("LIVE_LOGIN_DATA", LIVE_LOGIN_DATA, "live.bilibili.com"));
    store.addCookie(new BCookie("DedeUserID", DEDE_USER_ID, "live.bilibili.com"));
    store.addCookie(new BCookie("SESSDATA", SESS_DATA, "live.bilibili.com"));
    store.addCookie(new BCookie("ck_pv", CK_PV, "live.bilibili.com"));
    store.addCookie(new BCookie("DedeUserID__ckMd5", DEDE_USER_ID_CKMD5, "live.bilibili.com"));
    Session tempSession = new Session(client, store);
    for(int i = 0;i < 50; i++) {
        File file = new File("/captcha/captcha" + i + ".png");
        file.mkdirs();
        if (!file.exists()) file.createNewFile();
        ImageIO.write(ImageIO.read(HttpHelper.responseToInputStream(tempSession.getHttpHelper()
                        .createGetBiliLiveHost("/freeSilver/getCaptcha"))), "png",
                file);
        System.out.println(file.getAbsolutePath());
    }
}
 
開發者ID:cqjjjzr,項目名稱:BiliLiveLib,代碼行數:21,代碼來源:OCRUtilTest.java

示例5: removeCookie

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
/**
 * Remove a Cookie by name and path
 *
 * @param name cookie name
 * @param path cookie path
 */
@PublicAtsApi
public void removeCookie( String name, String path ) {

    BasicCookieStore cookieStore = (BasicCookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE);
    if (cookieStore != null) {

        List<Cookie> cookies = cookieStore.getCookies();
        cookieStore.clear();
        for (Cookie cookie : cookies) {
            if (!cookie.getName().equals(name) || !cookie.getPath().equals(path)) {
                cookieStore.addCookie(cookie);
            }
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:22,代碼來源:HttpClient.java

示例6: mimicCookieState

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet
 * @return
 */
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
    BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (Cookie seleniumCookie : seleniumCookieSet) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }
 
    return mimicWebDriverCookieStore;
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:20,代碼來源:FileDownloader.java

示例7: uploadFile

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
public WebResponse uploadFile(String path, String fname, InputStream in, 
              String stoken) throws ClientProtocolException, IOException {
  
  HttpPost post = new HttpPost(path);
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
  StringBody fn = new StringBody(fname, ContentType.MULTIPART_FORM_DATA);
  
  builder.addPart("fname", fn);
  builder.addBinaryBody("file", in, ContentType.APPLICATION_XML, fname);
  
  BasicCookieStore cookieStore = new BasicCookieStore();
  
  if (stoken != null) {
    BasicClientCookie cookie = new BasicClientCookie(
                Constants.SECURE_TOKEN_NAME, stoken);
    cookie.setDomain(TestConstants.JETTY_HOST);
    cookie.setPath("/");
    cookieStore.addCookie(cookie);
  }
  
  TestConstants.LOG.debug("stoken=" + stoken);
  HttpClient client = HttpClientBuilder.create().
                  setDefaultCookieStore(cookieStore).build();
  HttpEntity entity = builder.build();
  
  post.setEntity(entity);
  HttpResponse response = client.execute(post);
  
  String body;
  ResponseHandler<String> handler = new BasicResponseHandler();
  try {
    body = handler.handleResponse(response);
  } catch (HttpResponseException e) {
    return new WebResponse(e.getStatusCode(), e.getMessage());
  }
  
  return new WebResponse(response.getStatusLine().getStatusCode(), body);
}
 
開發者ID:osbitools,項目名稱:OsBiToolsWs,代碼行數:40,代碼來源:BasicWebUtils.java

示例8: testSyncWithCookies

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
@Test
public void testSyncWithCookies() throws IOException, NoSuchAlgorithmException, IllegalArgumentException {
	final URI url0 = BURL.parse(new MutableString("http://foo.bar/goo/first.html"));
	final URI url1 = BURL.parse(new MutableString("http://foo.bar/goo/second.html"));
	final String content0 = "";
	final String content1 = "";

	proxy = new SimpleFixedHttpProxy(true);

	proxy.add200(url0, "Set-cookie: cookie=hello; Domain: foo.bar", content0);
	proxy.add200(url1, "", content1);

	proxy.start();

	FetchData fetchData = new FetchData(testConfiguration);

	BasicCookieStore cookieStore = new BasicCookieStore();
	HttpClient httpClient = getHttpClient(new HttpHost("localhost", proxy.port()), false, cookieStore);

	// This shows we do receive cookies
	fetchData.fetch(url0, httpClient, null, null, false);
	Cookie[] cookie = FetchingThread.getCookies(url0, cookieStore, testConfiguration.cookieMaxByteSize);
	assertEquals("cookie", cookie[0].getName());
	assertEquals("hello", cookie[0].getValue());

	// This shows we do send cookies
	// First attempt: sending back the same cookies just received
	fetchData.fetch(url1, httpClient, null, null, false);
	assertTrue(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("hello"));
	// Second attempt: sending new cookies
	cookieStore.clear();
	BasicClientCookie clientCookie = new BasicClientCookie("returned", "cookie");
	clientCookie.setDomain("foo.bar");
	cookieStore.addCookie(clientCookie);
	fetchData.fetch(url1, httpClient, null, null, false);
	assertTrue(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("returned"));

	// This shows we do not send undue cookies
	cookieStore.clear();
	clientCookie.setDomain("another.domain");
	cookieStore.addCookie(clientCookie);
	fetchData.fetch(url1, httpClient, null, null, false);
	assertFalse(IOUtils.toString(fetchData.response().getEntity().getContent(), Charsets.ISO_8859_1).contains("returned"));

	System.out.println(Arrays.toString(FetchingThread.getCookies(url1, cookieStore, testConfiguration.cookieMaxByteSize)));

	fetchData.close();
}
 
開發者ID:LAW-Unimi,項目名稱:BUbiNG,代碼行數:49,代碼來源:FetchDataTest.java

示例9: createBasicCookieStore

import org.apache.http.impl.client.BasicCookieStore; //導入方法依賴的package包/類
public static CookieStore createBasicCookieStore(ConnectTokens tokens) {
    final BasicCookieStore store = new BasicCookieStore();
    store.addCookie(createCookie("itctx", tokens.getItctx()));
    store.addCookie(createCookie("myacinfo", tokens.getMyacinfo()));
    return store;
}
 
開發者ID:Roboroxx,項目名稱:itunesconnect-api,代碼行數:7,代碼來源:Utils.java


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