You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Juan Luis de Amaya Robles <Ju...@concatel.com> on 2006/02/02 19:48:50 UTC
Persistent connections
Hi everybody,
I tell you:
I have two urls to call (PHP pages). One sets a language variable in
session. Another returns data depending on the session var.
i think, i need stablish persistent connection to connect web pages with
session data.
When i call the first one url, it returns a cookie with a PHPSESSID
(it's a php). ok.
I understand that cookie is sended when I call the second one url, but i
get a incorrect second page, well, the language is not correct.
This is because the session is incorrect. I think.
What's the problem?
When i print the "isPersistent()" method is returned false. I must
configure anything else?
where the cookie is stored?
Thanks a lot!
A piece of my code is:
// 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();
System.out.println("Present cookies: ");
for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
System.out.println(" - " + c.toExternalForm()+", PERSISTENT:
"+c.isPersistent());
}
String pag = httpget.getResponseBodyAsString();
int idx = pag.indexOf("Welcome");
if (idx >= 0){
System.out.println(pag.substring(idx,idx+200));
}else{
System.out.println("No encontrado!");
}
// Release current connection to the connection pool once you
are done
httpget.releaseConnection();
Re: Persistent connections
Posted by Roland Weber <RO...@de.ibm.com>.
Hi Juan,
"Juan Luis de Amaya Robles" <Ju...@concatel.com> wrote on
02.02.2006 19:48:50:
> I have two urls to call (PHP pages). One sets a language variable in
> session. Another returns data depending on the session var.
>
> i think, i need stablish persistent connection to connect web pages with
> session data.
No. If connections were persistent, you wouldn't need a session.
> When i call the first one url, it returns a cookie with a PHPSESSID
> (it's a php). ok.
> I understand that cookie is sended when I call the second one url, but i
> get a incorrect second page, well, the language is not correct.
> This is because the session is incorrect. I think.
Quite possible. Make sure you use the same HttpClient object for both
requests.
Check out our cookie guide to see whether your problem is addressed there:
http://jakarta.apache.org/commons/httpclient/cookies.html
> When i print the "isPersistent()" method is returned false. I must
> configure anything else?
> where the cookie is stored?
HttpClient never stores persistent cookies anywhere but in memory.
By default, they are put into the state of the HttpClient object.
Make sure you use the same HttpClient object for both request. Don't
pass an explicit state to the second request. Try the "browser
compatibility" cookie spec, since some servers send domain names
without a leading dot.
hope that helps,
Roland
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org