共享的WebView和之间的HTTPClient饼干?饼干、WebView、HTTPClient

2023-09-06 13:22:17 作者:酷的没边儿

这是Android应用程序,我建设需要Web认证的用户进行数据呼叫。在Adobe AIR和更高版本的iPhone,我们通过在web视图,相当于页面呈现一个登录页面,设置时,随后的数据呼叫的用户登录使用相同的饼干罐,因此被看作是身份验证cookie中这样做。

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.

在Android版本,我使用的WebView验证用户的身份,然后一旦多数民众赞成做的,我做用DefaultHttpClient数据呼叫,但我似乎无法加载第二个呼叫的数据。

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.

有一些饼干疑难杂症我失踪?我想HttpClient的和web视图将共享相同的Cookie空间。难道我错了吗?

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

推荐答案

这是我的最后工作code段(其伪code作为它的某些部分被剥去了我的项目,有些东西像通过调用辛格尔顿MyApplication的更说明做什么,而不是它应该如何与最佳实践完成):

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