1
我想複製我在WEbView中收集的cookie,然後在我的urlopenconnections中使用它們。
默認情況下,我用將Cookie從WebView複製到HttpUrlOpenConnection
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
而且它完美地處理cookies在我HttpUrlOpenConnection請求。不過,它不會將webview中的廚師附加到我的請求中。 我試過
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String cookies = android.webkit.CookieManager.getInstance()
.getCookie(url);
HttpCookie cookie = new HttpCookie(url, cookies);
URI uri = null;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CookieManager c = new CookieManager();
c.getCookieStore().add(uri, cookie);
Log.d("cookie check", "All the cookies in a string:" + cookies);
// CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(с);
}
}
但是沒有成功。我如何從webview向我的請求攻擊cookie?