Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As compared with <code>DefaultHttpClient</code>, there are a few extra steps. The key difference is how to access the existing cookies in <code>HTTPURLConnection</code>:</p> <ol> <li>Call <code>CookieHandler.getDefault()</code> and cast the result to <code>java.net.CookieManager</code>.</li> <li>With the cookie manager, call <code>getCookieStore()</code> to access the cookie store.</li> <li>With the cookie store, call <code>get()</code> to access the list of cookies for the given <code>URI</code>.</li> </ol> <p>Here's a complete example:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { // Get cookie manager for WebView // This must occur before setContentView() instantiates your WebView android.webkit.CookieSyncManager webCookieSync = CookieSyncManager.createInstance(this); android.webkit.CookieManager webCookieManager = CookieManager.getInstance(); webCookieManager.setAcceptCookie(true); // Get cookie manager for HttpURLConnection java.net.CookieStore rawCookieStore = ((java.net.CookieManager) CookieHandler.getDefault()).getCookieStore(); // Construct URI java.net.URI baseUri = null; try { baseUri = new URI("http://www.example.com"); } catch (URISyntaxException e) { // Handle invalid URI ... } // Copy cookies from HttpURLConnection to WebView List&lt;HttpCookie&gt; cookies = rawCookieStore.get(baseUri); String url = baseUri.toString(); for (HttpCookie cookie : cookies) { String setCookie = new StringBuilder(cookie.toString()) .append("; domain=").append(cookie.getDomain()) .append("; path=").append(cookie.getPath()) .toString(); webCookieManager.setCookie(url, setCookie); } // Continue with onCreate ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload