Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29743

Not able to set cookie for 10.0.2.2 on android emulator

$
0
0

I am trying to set cookie using CookieManager on Oreo (https://developer.android.com/reference/android/webkit/CookieManager#setCookie(java.lang.String,%20java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.Boolean%3E) and above for a Webview, which loads from a local server running on my laptop (let's say localhost:8080) using 10.0.2.2:8080

As we all know, For an android emulator, localhost address is referred by 10.0.2.2

As far as I recall One was able to set cookies for 10.0.2.2

Also Is there a way to debug why a cookie setting failed? I am checking cookies are set or not via chrome inspector (chrome://inspect)

Here is the use case (react-native but it uses regular CookieManager under the hood) :

import CookieManager from '@react-native-community/cookies';

// Set cookies from a response header
// This allows you to put the full string provided by a server's Set-Cookie 
// response header directly into the cookie store.
CookieManager.setFromResponse(
  'http://10.0.2.2:8080', 
  'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly')
    .then((res) => {
      // `res` will be true or false depending on success.
      console.log('CookieManager.setFromResponse =>', res);
    });

Viewing all articles
Browse latest Browse all 29743

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>