我已經做了你的相反:我登錄與循環J Android的異步HTTP客戶端,並希望會話cookie應用到網頁視圖,爲同一個網站。我不知道它是否會幫助你,但是,我將發佈我的代碼以便複製Cookie。也許看到這個過程將幫助你尋找你需要的項目......將cookies從webview複製到HTTP。我無法提供進一步的幫助,因爲我在Android上相當新穎。 (當然,我改編自別人的帖子我的代碼。)
類變量聲明:
private AsyncHttpClient loopjClient = new AsyncHttpClient();
private PersistentCookieStore myCookieStore;
的onCreate()初始化:
myCookieStore = new PersistentCookieStore(this);
loopjClient.setCookieStore(myCookieStore);
HTTP登錄後:
// get cookies from the generic http session, and copy them to the webview
CookieSyncManager.createInstance(getActivity().getApplicationContext());
CookieManager.getInstance().removeAllCookie();
CookieManager cookieManager = CookieManager.getInstance();
List<Cookie> cookies = myCookieStore.getCookies();
for (Cookie eachCookie : cookies) {
String cookieString = eachCookie.getName() + "=" + eachCookie.getValue();
cookieManager.setCookie("http://www.example.com", cookieString);
//System.err.println(">>>>> " + "cookie: " + cookieString);
}
CookieSyncManager.getInstance().sync();
// holy ****, it worked; I am automatically logged in for the webview session
請注意,loopj就像webview,因爲所有的cookie管理和發送都是自動的。我只是複製域的所有cookie。我認爲你會沒事的,也一樣......因此,不管是從第一頁還是第二頁開始。
這工作,我不知道爲什麼相反不起作用! – User3