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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.