You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Beg, Mohsin" <mo...@certive.com> on 2004/10/13 10:22:02 UTC

How to share a single http session across multiple http posts

Hi,

I have a need where I need to do multiple separate posts to a URL
but need all the posts to share the same session context.

I am able to do the initial login to a URL successfully as shown below.
It is unclear to me how to "reuse" any instances or set some parameters
to make sure that all subsequent posts are for the same session. The
behavior I need is approximately like that of a browser.

Can someone provide any pointers ?

Sincerely,

-Mohsin
ps: My webserver is running jetty4.2.19 on WinXP under jdk1.4.2


        HttpClient httpClient = new HttpClient();
        httpClient.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT,
"http");
        httpClient.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
        
        NameValuePair msgTransaction = 
        	new NameValuePair("XML", LOGIN_XML);
        PostMethod postMethod = new PostMethod(SERVER_URL);

        postMethod.setRequestHeader("Content-type",
                PostMethod.FORM_URL_ENCODED_CONTENT_TYPE);
        postMethod.setUseExpectHeader(true);
        postMethod.setHttp11(false);
        
        postMethod.addParameter(msgTransaction);
        
        try {
	        int statusCode = httpClient.executeMethod(postMethod);
	        String response = new String(postMethod.getResponseBody(),
	
postMethod.getResponseCharSet());
	        System.out.println(response);
	} catch (Exception e) {
	        e.printStackTrace();
	} finally { 
	       postMethod.releaseConnection();
	}

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