Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

cookies in apache.httpClient

807606May 30 2007 — edited May 30 2007
hi all,

I've encountered this problem to which i cant find a solution for ages now. I have a program that programatically logs into a site, and checks some pages within it. all stages work well, cookie handling working (after numerous tries...)

The problem starts just at my final stage (of course). I am trying to POST with certain cookies, and they just arent sent! the httpState has them, i print them out, but they dont appear in my sniffer program. this obviously makes my last POST fail.

My code is LONG, so i'll just show bits and pieces of it:
HttpClient client =	new HttpClient();
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); //login fails without this
client.getParams().setParameter("http.protocol.single-cookie-header", true); //login fails without this
client.getState().addCookie(cookies); //cookies is an array of cookies - DAH 
...
PostMethod post = new PostMethod (url);
post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
statusCode = client.executeMethod(post);


Some clarifications:
1. the client is not new for the POST - its the same one i use for all my interaction.
2. the POST method is new.
3. the cookies i specifically saved in an earlier stage, not because i wanted, but because i thought it could help - it didnt.
4. i read somewhere that cookies are sent from the client if it received them in the previous response - i do NOT get these cookies (or any others) with the previous response.
5. Obviously, when performed in my browser, this flow is smooth...

Alright, thanks in advance for any help.
Yotam.

Message was edited by:
Yo_So
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2007
Added on May 30 2007
0 comments
345 views