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


Java BasicCookieStore類代碼示例

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


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

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public QMailHttpClient getHttpClient() throws MessagingException {
    if (httpClient == null) {
        httpClient = httpClientFactory.create();
        // Disable automatic redirects on the http client.
        httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        httpContext = new BasicHttpContext();
        authCookies = new BasicCookieStore();
        httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);

        SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(hostname, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient");
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa);
        } catch (KeyManagementException kme) {
            Timber.e(kme, "KeyManagementException in getHttpClient");
            throw new MessagingException("KeyManagementException in getHttpClient: ", kme);
        }
    }
    return httpClient;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:26,代碼來源:WebDavStore.java

示例3: connect

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public Map<String, String> connect(String url, Map<String, Object> parameters) throws ManagerResponseException {

        Map<String, String> response = new HashMap<String, String>();
        CloseableHttpClient httpclient = HttpClients.createDefault();
        List<NameValuePair> nvps = new ArrayList<>();
        nvps.add(new BasicNameValuePair("j_username", (String) parameters.get("login")));
        nvps.add(new BasicNameValuePair("j_password", (String) parameters.get("password")));
        localContext = HttpClientContext.create();
        localContext.setCookieStore(new BasicCookieStore());
        HttpPost httpPost = new HttpPost(url);
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nvps));
            CloseableHttpResponse httpResponse = httpclient.execute(httpPost, localContext);
            ResponseHandler<String> handler = new CustomResponseErrorHandler();
            String body = handler.handleResponse(httpResponse);
            response.put(BODY, body);
            httpResponse.close();
        } catch (Exception e) {
            authentificationUtils.getMap().clear();
            throw new ManagerResponseException(e.getMessage(), e);
        }

        return response;
    }
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:25,代碼來源:RestUtils.java

示例4: getuCookie

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

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
@Before
public void setUp() throws IOException {

    when(mockHubConnection.createHubProxy("CoreHub")).thenReturn(mockHubProxy);

    HttpResponse mockResponse = createResponse(HttpStatus.SC_OK,STATUS_OK_TEXT,"Bittrex");

    when(mockHttpClientContext.getCookieStore()).thenReturn(new BasicCookieStore());
    when(mockHttpClient.execute(argThat(UrlMatcher.matchesUrl("https://bittrex.com")),eq(mockHttpClientContext)))
            .thenReturn(mockResponse);

    when(mockHttpFactory.createClient()).thenReturn(mockHttpClient);
    when(mockHttpFactory.createClientContext()).thenReturn(mockHttpClientContext);
    when(mockHttpFactory.createHubConnection(any(),any(),anyBoolean(),any())).thenReturn(mockHubConnection);

    bittrexExchange = new BittrexExchange(0,"apikey","secret", mockHttpFactory);
    lambdaCalled = false;
}
 
開發者ID:CCob,項目名稱:bittrex4j,代碼行數:19,代碼來源:BittrexExchangeTest.java

示例6: HttpUtils

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
private HttpUtils(HttpRequestBase request) {
	this.request = request;

	this.clientBuilder = HttpClientBuilder.create();
	this.isHttps = request.getURI().getScheme().equalsIgnoreCase("https");
	this.config = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
	this.cookieStore = new BasicCookieStore();

	if (request instanceof HttpPost) {
		this.type = 1;
		this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());

	} else if (request instanceof HttpGet) {
		this.type = 2;
		this.uriBuilder = new URIBuilder();

	} else if (request instanceof HttpPut) {
		this.type = 3;
		this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());

	} else if (request instanceof HttpDelete) {
		this.type = 4;
		this.uriBuilder = new URIBuilder();
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:26,代碼來源:HttpUtils.java

示例7: 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

示例8: HttpTransportClient

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public HttpTransportClient(int retryAttemptsNetworkErrorCount, int retryAttemptsInvalidStatusCount) {
    this.retryAttemptsNetworkErrorCount = retryAttemptsNetworkErrorCount;
    this.retryAttemptsInvalidStatusCount = retryAttemptsInvalidStatusCount;

    CookieStore cookieStore = new BasicCookieStore();
    RequestConfig requestConfig = RequestConfig.custom()
            .setSocketTimeout(SOCKET_TIMEOUT_MS)
            .setConnectTimeout(CONNECTION_TIMEOUT_MS)
            .setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
            .setCookieSpec(CookieSpecs.STANDARD)
            .build();

    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

    connectionManager.setMaxTotal(MAX_SIMULTANEOUS_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(MAX_SIMULTANEOUS_CONNECTIONS);

    httpClient = HttpClients.custom()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig)
            .setDefaultCookieStore(cookieStore)
            .setUserAgent(USER_AGENT)
            .build();
}
 
開發者ID:VKCOM,項目名稱:vk-java-sdk,代碼行數:25,代碼來源:HttpTransportClient.java

示例9: createContext

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

    BasicHttpContext context = CACHED_CONTEXTS.get(targetHost);

    if (context == null) {

        log.trace("creating and configuring new HttpContext for system user");
        context = basicAuthConfigurator.createContext(targetHost);

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

        log.trace("caching HttpContext for system user");
        CACHED_CONTEXTS.put(targetHost, context);
    }
    else {

        log.trace("using cached HttpContext for system user");
    }

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

示例10: authenticate

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public boolean authenticate(String username, String password)
{
  closeQuietly();
  cookieStore = new BasicCookieStore();
  httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).setDefaultCookieStore(cookieStore).build();
  String url = concatePath(baseUrl, "index.php");
  String result = internalHttpPost(url, new BasicNameValuePair("username", username), new BasicNameValuePair("password", password),
      new BasicNameValuePair("action", "login"), new BasicNameValuePair("view", "console"));
  if (result.contains("loginForm") == true) {
    log.warn("Authentication for user '" + username + "' wasn't sucessful.");
    return false;
  }
  log.info("Authentication for user '" + username + "' was sucessful.");
  authorized = true;
  return true;
}
 
開發者ID:kreinhard,項目名稱:OpenViSu,代碼行數:17,代碼來源:ZMClientSession.java

示例11: 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

示例12: createContext

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

示例13: getHttpClient

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public WebDavHttpClient getHttpClient() throws MessagingException {
    if (mHttpClient == null) {
        mHttpClient = mHttpClientFactory.create();
        // Disable automatic redirects on the http client.
        mHttpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        mContext = new BasicHttpContext();
        mAuthCookies = new BasicCookieStore();
        mContext.setAttribute(ClientContext.COOKIE_STORE, mAuthCookies);

        SchemeRegistry reg = mHttpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(mHost, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Log.e(LOG_TAG, "NoSuchAlgorithmException in getHttpClient: " + nsa);
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
        } catch (KeyManagementException kme) {
            Log.e(LOG_TAG, "KeyManagementException in getHttpClient: " + kme);
            throw new MessagingException("KeyManagementException in getHttpClient: " + kme);
        }
    }
    return mHttpClient;
}
 
開發者ID:scoute-dich,項目名稱:K9-MailClient,代碼行數:26,代碼來源:WebDavStore.java

示例14: createHttpClient

import org.apache.http.impl.client.BasicCookieStore; //導入依賴的package包/類
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
    s_logger.info("Creating new HTTP connection pool and client");
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
    final BasicCookieStore cookieStore = new BasicCookieStore();
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
    connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
    final RequestConfig requestConfig = RequestConfig.custom()
                                                     .setCookieSpec(CookieSpecs.DEFAULT)
                                                     .setMaxRedirects(maxRedirects)
                                                     .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
                                                     .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
                                                     .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
                                                     .build();
    return HttpClientBuilder.create()
                            .setConnectionManager(connManager)
                            .setRedirectStrategy(new LaxRedirectStrategy())
                            .setDefaultRequestConfig(requestConfig)
                            .setDefaultCookieStore(cookieStore)
                            .setRetryHandler(new StandardHttpRequestRetryHandler())
                            .build();
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:23,代碼來源:HttpClientHelper.java

示例15: 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


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