2

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.

  1. the page of webview is loaded.
  2. read cookies from webview.
  3. 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.

user1705636
  • 233
  • 1
  • 6
  • 14

1 Answers1

0

you need to set the cookie to your HttpPost object as well, try this:

httpPost.setHeader("Cookie", "PHPSESSID=" + httpCookie.getValue());

where httpPost is an instance of org.apache.http.client.methods.HttpPost

Zennichimaro
  • 5,236
  • 6
  • 54
  • 78