I'm making a progam on Android. It has one button and one WebView. If I click the button, It send post message to a web server. (using httpurlconnection) The webview load a page from the same server. I want to sync cookies between core and webview. I found the method from core to webview. But, I couln't find a method from webview to core.
I tried these order.
- the page of webview is loaded.
- read cookies from webview.
add these cookies to core cookies using HttpCookie.
URI uri = new URI(url);
HttpCookie httpCookie = new HttpCookie(cookie.getKey(), cookie.getValue());
((java.net.CookieManager) CookieHandler.getDefault()).getCookieStore().add(uri, httpCookie);
but It doesn't working. what is wrong? please advice me about it. Thank you in advance.
you need to set the cookie to your HttpPost object as well, try this:
where httpPost is an instance of org.apache.http.client.methods.HttpPost