ConnectionRequest and Cookie

71 views
Skip to first unread message

State Thirteen

unread,
Nov 10, 2013, 5:01:03 PM11/10/13
to codenameone...@googlegroups.com
Hi,

What should I do to set a cookie header in the ConnectionRequest?
I have tried to set a Cookie like this

Date date=new Date();
Cookie ljsession = new Cookie();
ljsession.setDomain("livejournal.com");
ljsession.setName("ljsession");
ljsession.setValue(authCookie);
ljsession.setPath("/");
ljsession.setExpires(date.getTime()+24*60*60*1000);

But in request headers I am getting only  
cookie=[vertical_tags=1383827150%7Cvaut]

Shai Almog

unread,
Nov 11, 2013, 12:11:13 AM11/11/13
to codenameone...@googlegroups.com
Hi,
normally cookies sent by the server should automatically be returned to that domain so you don't really need to explicitly set a cookie.

The cookie object is one that's returned its not designed for adding cookies and we don't have that option. You can explicitly invoke add header to manually add the cookie header. The server will then start returning the cookie and you will no longer need to set it.

State Thirteen

unread,
Nov 11, 2013, 1:59:05 AM11/11/13
to codenameone...@googlegroups.com
Normally yes, I don't need to send the cookie. But in my case I have to form and send it manually because of specific challenge authentication method.
I have tried 
requestElement.addRequestHeader("cookie", "ljsession="+authCookie);
but nothing changed 

Shai Almog

unread,
Nov 11, 2013, 12:13:02 PM11/11/13
to codenameone...@googlegroups.com
That should work, did you use the HTTP monitor to see what is sent/received?
Is the header sent?
Is Set-Cookie received? Where does this fail?

State Thirteen

unread,
Nov 11, 2013, 12:15:21 PM11/11/13
to codenameone...@googlegroups.com
I am using Network monitor in simulator and in request headers I see only cookie=[vertical_tags=1383827150%7Cvaut]

Shai Almog

unread,
Nov 11, 2013, 12:50:30 PM11/11/13
to codenameone...@googlegroups.com
OK I see a potential problem there. I'll add a method called:
protected String initCookieHeader(String cookie)

You will then be able to override it and add your value to the cookie header that's already sent.
We intend to make an update to the plugin this week so you should be able to use it then.

State Thirteen

unread,
Nov 11, 2013, 1:07:57 PM11/11/13
to codenameone...@googlegroups.com
Thank you. That would be useful ) 
Reply all
Reply to author
Forward
0 new messages