views:

297

answers:

3

An Android app I am building requires web authentication for users to make data calls. In Adobe AIR and later the iPhone, we did this by rendering a login page in a webview-equivalent page and setting a cookie when the user signs in. Subsequent data calls use the same Cookie Jar and so are seen as authenticated.

In the Android version, I authenticate the user using a WebView and then once thats done, I make a data call using DefaultHttpClient, however I cant seem to load the data on the second call.

Is there some cookie gotcha I am missing? I imagine the HTTPClient and WebView would share the same Cookie space. Am I wrong?

A: 

I want to do the exact same thing. Did you ever figure this out?

Jack
Yeah, I got it to work. Had to copy all the cookies from the webview and place them in HTTPClient instance's CookieJar. I'll post the code up on my blog soon.
Arpit
I can't find the post on your blog, can you link me to it?
Aymon Fournier
A: 

Here is my code snippet that finally worked (its pseudo code as in parts of it were ripped out of my project and some things like calling MyApplication via a Singleton were more to illustrate what to do rather than how it should be done with best practices):

http://gist.github.com/610754

Arpit
+1  A: 

Here is my code snippet that finally worked (its pseudo code as in parts of it were ripped out of my project and some things like calling MyApplication via a Singleton were more to illustrate what to do rather than how it should be done with best practices):

http://gist.github.com/610754

Arpit