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


Java HttpState.addCookie方法代碼示例

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


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

示例1: getClient

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private void getClient(){
   CONTACT_URL = OscarProperties.getInstance().getProperty("TELEPLAN_URL",CONTACT_URL);
   HttpState initialState = new HttpState();
    // Initial set of cookies can be retrieved from persistent storage and 
    // re-created, using a persistence mechanism of choice,
    Cookie mycookie = new Cookie("moh.hnet.bc.ca","mycookie", "stuff", "/", null, false);        // and then added to your HTTP state instance
    initialState.addCookie(mycookie);

    // Get HTTP client instance
    //HttpClientParams hcParams = new HttpClientParams();
    //hcParams.setParameter("User-Agent","TeleplanPerl 1.0");
    
    httpclient = new HttpClient(); //hcParams);
    httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    httpclient.setState(initialState);
    
    httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    httpclient.getParams().setParameter("User-Agent","TeleplanPerl 1.0");  
	
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:21,代碼來源:TeleplanAPI.java

示例2: initHttpClient

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
protected void initHttpClient() {
    if (httpClient == null) {
        httpClient = new HttpClient();
    }
    params = new HttpClientParams();
    myCookie = new Cookie(".secq.me", "mycookie", "stuff",
            "/", null, false);
    initialState = new HttpState();
    initialState.addCookie(myCookie);
    httpClient.setParams(params);
    httpClient.setState(initialState);
    httpClient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

}
 
開發者ID:SECQME,項目名稱:watchoverme-server,代碼行數:15,代碼來源:BaseRestWorker.java

示例3: addCookie

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
/**
 * add cookie to state
 * @param state
 * @param cookie
 */
private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) {
    int index = cookie.indexOf('=');
    state.addCookie(new Cookie(host, cookie.substring(0, index),
            cookie.substring(index + 1), path,
            null, secure));
}
 
開發者ID:JockiHendry,項目名稱:ireport-fork,代碼行數:12,代碼來源:CommonsHTTPSender.java

示例4: mimicCookieState

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
    HttpState mimicWebDriverCookieState = new HttpState();
    for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
        Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(), seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(), seleniumCookie.isSecure());
        mimicWebDriverCookieState.addCookie(httpClientCookie);
    }
    return mimicWebDriverCookieState;
}
 
開發者ID:jhc-systems,項目名稱:redsniff,代碼行數:9,代碼來源:FileDownloader.java

示例5: download

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
private boolean download(String src, String local, File destination, String playSession) {
    try {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        URI u = new URI(src);
        String url;
        if(u.isAbsolute()) {
            url = u.toString();
        } else {
            url = "http://localhost:9000" + u.toString();
            HttpState state = new HttpState();
            Cookie session = new Cookie("localhost", "PLAY_SESSION",
                    playSession, "/", -1, false);
            state.addCookie(session);
            client.setState(state);
        }
        HttpMethod method = new GetMethod(url);
        method.setFollowRedirects(true);
        client.executeMethod(method);
        if(method.getStatusCode() == 200) {
            InputStream in = method.getResponseBodyAsStream();
            File f = new File(destination, local);
            f.getParentFile().mkdirs();
            FileOutputStream out = new FileOutputStream(new File(destination, local));
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(out);
            method.releaseConnection();
            return true;
        } else {
            method.releaseConnection();
            return false;
        }
    } catch(Exception e) {
        return false;
    }
}
 
開發者ID:uq-eresearch,項目名稱:aorra,代碼行數:37,代碼來源:HtmlZip.java

示例6: addSsoCredential

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public static void addSsoCredential(HttpMethod method, HttpState state, String defaultForwardHost) {
	try {
		String name=SsoUtil.getSsoTokenName();
		String value=SsoUtil.getSsoToken();
		if (StringUtils.isEmpty(value)) {
			if (log.isDebugEnabled()) log.debug("no value for SsoCredential ["+name+"]");
		} else {
			if (log.isDebugEnabled()) log.debug("constructing SsoCredentialCookie ["+name+"]");
			Cookie ssoCookie = new Cookie();
			ssoCookie.setName(name);
		
			ssoCookie.setValue(value);
			String forwardHost;
			try {
				URI uri = method.getURI();
				forwardHost = uri.getHost();
				if (StringUtils.isEmpty(forwardHost)) {
					if (log.isDebugEnabled()) log.debug("did not find host from URI ["+uri.getURI()+"], will use default ["+defaultForwardHost+"] for SSO credential cookie");
					forwardHost=defaultForwardHost;
				}
			} catch (Throwable t) {
				log.warn("could not extract host from URI", t);
				forwardHost = defaultForwardHost;					
			}
			ssoCookie.setDomain(forwardHost);
			// path must have a value, otherwise cookie is not appended to request
			ssoCookie.setPath("/");
			if (log.isDebugEnabled()) log.debug("set SSOcookie attributes: domain ["+ssoCookie.getDomain()+"] path ["+ssoCookie.getPath()+"]");
			state.addCookie(ssoCookie);
		}
		
	} catch (Exception e) {
		log.warn("could not obtain SsoToken: "+e.getMessage());
	}
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:36,代碼來源:SsoUtil.java

示例7: CatalogRequest

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
public CatalogRequest(URL cswServerUrl) {
    this.host    = cswServerUrl.getHost();
    this.port    = cswServerUrl.getPort();
    this.protocol= cswServerUrl.getProtocol();

    setMethod(Method.POST);
    Cookie cookie = new Cookie();
    HttpState state = new HttpState();
    state.addCookie(cookie);
    client.setState(state);
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
}
 
開發者ID:OpenGeoportal,項目名稱:ogpHarvester,代碼行數:13,代碼來源:CatalogRequest.java

示例8: main

import org.apache.commons.httpclient.HttpState; //導入方法依賴的package包/類
/**
 *
 * Usage:
 *          java CookieDemoApp http://mywebserver:80/
 *
 *  @param args command line arguments
 *                 Argument 0 is a URL to a web server
 *
 *
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Usage: java CookieDemoApp <url>");
        System.err.println("<url> The url of a webpage");
        System.exit(1);
    }
    // Get target URL
    String strURL = args[0];
    System.out.println("Target URL: " + strURL);

    // Get initial state object
    HttpState initialState = new HttpState();
    // Initial set of cookies can be retrieved from persistent storage and 
    // re-created, using a persistence mechanism of choice,
    Cookie mycookie = new Cookie(".foobar.com", "mycookie", "stuff", "/", null, false);
    // and then added to your HTTP state instance
    initialState.addCookie(mycookie);

    // Get HTTP client instance
    HttpClient httpclient = new HttpClient();
    httpclient.getHttpConnectionManager().
        getParams().setConnectionTimeout(30000);
    httpclient.setState(initialState);

    // RFC 2101 cookie management spec is used per default
    // to parse, validate, format & match cookies
    httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    // A different cookie management spec can be selected
    // when desired

    //httpclient.getParams().setCookiePolicy(CookiePolicy.NETSCAPE);
    // Netscape Cookie Draft spec is provided for completeness
    // You would hardly want to use this spec in real life situations
    //httppclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    // Compatibility policy is provided in order to mimic cookie
    // management of popular web browsers that is in some areas 
    // not 100% standards compliant

    // Get HTTP GET method
    GetMethod httpget = new GetMethod(strURL);
    // Execute HTTP GET
    int result = httpclient.executeMethod(httpget);
    // Display status code
    System.out.println("Response status code: " + result);
    // Get all the cookies
    Cookie[] cookies = httpclient.getState().getCookies();
    // Display the cookies
    System.out.println("Present cookies: ");
    for (int i = 0; i < cookies.length; i++) {
        System.out.println(" - " + cookies[i].toExternalForm());
    }
    // Release current connection to the connection pool once you are done
    httpget.releaseConnection();
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:65,代碼來源:CookieDemoApp.java


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