Dependent Origination

Iphone app: send cookies for ajax requests

Posted on: December 15, 2010

I am writing an Iphone app right now. When I use it from Chrome or Mobile Safari, everything works out fine. The cookie I saved will be sent up again to the server on subsequent requests. However, when I launch the app from the home screen, everything breaks down and there is never a cookie sent up.

It is very strange since even if launched from the home screen, it is still Mobile Safari that is working behind the scenes. One tricky point I realized up front is that when launching from the home screen, it is file://index.html that is the starting point, in contrast to a well-formed url when executing inside Mobile Safari by me. So the domain is not the same as the domain I am setting the cookies to. However, the server domain is always the same so as long as I set the cookie for my server domain they really should be sent up every time.

This was driving me nuts until yesterday. We actually have an echo server that can dump out the entire HTTP request. There is probably Unix command that can do this and I should dig them out. Anyway we confirmed that the app is not sending up the cookies even though it has it. You can check out under Preferences and Content Settings to see the cookie in Chrome.

Now stackoverflow comes to rescue. There is a fix, which you have to ask PhoneGap to save cookies for AJAX requests. Yes, the initial setting of cookie happens over an AJAX request/response and subsequent AJAX calls will not supply the cookie unless PhoneGap initialization is modified.

Glad this is solved since it is a very annoying and perplexing problem. And to add to the frustration, people use different terms to talk about these things so it is very hard to google., as the environment and the software are so new.

Advertisements

1 Response to "Iphone app: send cookies for ajax requests"

啊刚看到说你得肺炎了?!希望现在好多了。多保重!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

December 2010
M T W T F S S
« Nov   Jan »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Twitter

Flickr Photos

Advertisements
%d bloggers like this: