commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dongsheng Song <dongsheng.s...@gmail.com>
Subject How to clear cookies before connect server with httpclient 3.0-dev?
Date Fri, 26 Nov 2004 06:30:32 GMT
Whey HttpState only has addCookie/purgeExpiredCookies method, but no
purgeAllCookies mothod ?

How to remove all cookies in the code ?

        HostConfiguration config = new HostConfiguration();
        config.setProxy(record.host, record.port);        

        HttpConnectionManagerParams hcp = new HttpConnectionManagerParams();
        hcp.setConnectionTimeout(TIMEOUT_CONNECT);
        hcp.setSoTimeout(TIMEOUT_READ);        
        SimpleHttpConnectionManager hcm = new SimpleHttpConnectionManager();
        hcm.setParams(hcp);
        
        HttpClient hc = new HttpClient();
        hc.setHostConfiguration(config);
        hc.setHttpConnectionManager(hcm);
        
        HttpMethod method = new GetMethod(url);        
        int statusCode = hc.executeMethod(config, method, new HttpState());
        if (statusCode != 200) {
            throw new ConnectException("GET '" + url + "' fail");
        }

        InputStream is = method.getResponseBodyAsStream();
        if (is == null) {
            throw new IOException("No response body");
        }

        int nb = 0, rb = 0;
        byte[] buf = new byte[65536];
        while ((rb = is.read(buf)) >= 0) {
            nb += rb;
        }
        is.close();
        method.releaseConnection();
        hcm.closeIdleConnections(0);

Thanks for some help

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message