iPhone xmlhttp cookies?

129 views
Skip to first unread message

JayRafferty

unread,
May 22, 2009, 3:15:53 AM5/22/09
to phonegap
Been trying for over a day to get cookies to be set and posted
properly in phonegap on the iphone.

My problem is that I need to read the 'Set-Cookie' header during a
302 redirect on an ajax request.

I've tried using getResponseHeader('Set-Cookie'); which works for non
302 redirects but I can't manage to read the Set-Cookie header on a
302 redirect.

I was under the impression that uiwebview should have a cookie jar
built in so I didn't have to worry about getting and posting cookies
at all?

Any suggestions would be much appreciated.

Thanks,

Jay

JayRafferty

unread,
May 24, 2009, 8:26:56 AM5/24/09
to phonegap
Wohooo!

I solved my problem, have no idea if this is the right way to go about
it or not but this is because the cookieacceptpolicy is default to
only visited and with an ajax request the site is counted as external.
I added the following lines to line 41 of PhoneGapDelegate.m:

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

If this is the wrong way to do it someone please tell me because to be
honest I do NOT understand objective C at all.

Hope this helps someone else :)

iamcam (Cameron Perry)

unread,
May 25, 2009, 11:05:43 AM5/25/09
to phonegap
Awesome fix! Thanks for figuring that out.

Is there any way we can get that patched in one of the main branches?

jakesankey

unread,
May 26, 2009, 1:47:29 AM5/26/09
to phonegap
I am creating a game for iPhone that I have a cookie set the
highscore. It works great on the desktop Safari, but no luck on the
iPhone. I have put this bit of code you suggested in lines 42-44 of
the PhoneGapDelegate.m file, but still no luck. My app is an offline,
self-contained app. Any advice?
Reply all
Reply to author
Forward
0 new messages