tags:

views:

213

answers:

1

In my iPhone app, I want to be able to reuse the same server-side session when my app restarts. A session on the server is identified by a cookie, which is sent on each request. When I restart the app, that cookie is gone and I can't use the same session anymore.

What I noticed when I used the NSHTTPCookieStorage to look up the cookie I got from the server, is that [cookie isSessionOnly] returns YES. I get the impression that this is why cookies are not saved across restarts of my app. What would I have to do to make my cookie NOT session only? What HTTP headers do I have to send from the server?

A: 

I believe it's up to the server to decide whether or not the cookie is session-only, you can't do anything about it.

Tom Irving
No, it's really the client (iPhone app) that throws the session cookie away. The session still exists on the server.
Tom van Zummeren
Right, but the server will tell the iPhone app that the cookie is session only.
Tom Irving
Yes, and that's through HTTP. So I'm looking for the correct headers to send from the server, to tell the iPhone app that it can keep the cookie around longer.
Tom van Zummeren
Oh, I see what you're looking for now, I apologise.How are you setting the cookie at the moment?
Tom Irving
No problem :) I have a Java application running in Tomcat, which generates the following HTTP header to set the cookie on the client -> Set-Cookie: JSESSIONID=3E576D79DED4DAEDCB5E24A674AA19C7; Path=/
Tom van Zummeren
You need to set an expiration date, otherwise the cookie is assumed to be session only.
Tom Irving