<p dir="auto">it is not working in android (react native app)</p>
<p dir="auto">I'n new with React Native, and I was playing around with components and http ajax request, and all went fine with iOs emulator, until I thought to test on Android emulator.</p>
<p dir="auto">This is my Http class:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'url-search-params-polyfill';
import axios from 'axios';
import { AsyncStorage } from 'react-native';
import Rx from 'rxjs/Rx';

let _HttpServiceInstance = null;

class HttpService {

  constructor(envStr) {
    console.log('DEFAULT', axios.defaults);
    if(!_HttpServiceInstance){
      this.__proto__.ghtnk = null;
      axios.defaults.baseURL = this.getBaseUrlApi()[envStr || 'DEV'];
      axios.interceptors.response.use(
        (resp) =&gt; {
          let ghresp = resp.data || resp;
          ghresp.status = resp.data ? resp.data.status : resp.status;
          return ghresp;
        },
        (err) =&gt; {
          if( err.status === 401 ){
              this.removeToken();
              // go to login
          }
          return Promise.reject(err);
        }
      )
      _HttpServiceInstance = this;
    }
    return _HttpServiceInstance;
  }

  getBaseUrlApi = () =&gt; {
    return {
      DEV : 'https://dev-api.domainname.com/',
      TEST: 'https://test-api.domainname.com/',
      QA  : 'https://qa-api.domainname.com/',
      LIVE: 'https://api.domainname.com/',
    };
  }

  switchBaseUrlApi(envStr) {
    axios.defaults.baseURL = this.getBaseUrlApi()[envStr];
  }

  getToken = (callback) =&gt; {
      let promise = AsyncStorage.getItem('ghtkn');
      if( callback ){
        promise.then(callback, () =&gt; { console.log('getToken: ', err) });
      }
      else return promise;
  };

  setToken = (token) =&gt; {
    return AsyncStorage.setItem('ghtkn', token);
  };

  removeToken = () =&gt; {
    AsyncStorage.removeItem('ghtkn');
  };

  setAuthHeaders = (callback, noNeedToken) =&gt; {
    if ( noNeedToken ) {
      callback(); return;
    }
    this.getToken(
      (token) =&gt; {
        if (token) {
          axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
          callback();
        }
        else{ console.log('NO TOKEN PRESENT'); }
      },
      (err) =&gt; { console.log('GET TOKEN: ', err); },
    );
  };

  // GET
  get = (url) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders((token) =&gt; {
      axios.get(url).then(
        (data) =&gt; { subject.next(data); },
        (err) =&gt; { console.log('GET: ', err); }
      );
    });
    return subject;
  };

  // POST
  post = (url, payload, noNeedToken) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders(() =&gt; {
      axios.post( url, this.setParams(payload)).then(
        (resp) =&gt; { subject.next(resp); },
        (err) =&gt; {
          console.log('POST ERROR');
          console.log(err.request, Object.keys(err) );
          subject.error(err);
        }
      );
    }, noNeedToken);
    return subject;
  };

  // PUT
  put = (url, payload) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders((token) =&gt; {
      axios.put( url, this.setParams(payload)).then(
        (resp) =&gt; { subject.next(resp); },
        (err) =&gt; { console.log('PUT: ', err); }
      );
    });
    return subject;
  };

  // LOGIN
  login = (user, pw) =&gt; {
    return this.post('user/authentication', {username: user, password: pw}, true)
               .do((resp) =&gt; { this.setToken(resp.token); })
  };

  setParams = (jsonParams) =&gt; {
    let params = new URLSearchParams();
    for(param in jsonParams){
      if( jsonParams.hasOwnProperty(param) ){
        params.append(param, jsonParams[param]);
      }
    }
    return params;
  };

}

export { HttpService };"><pre class="notranslate"><code class="notranslate">import 'url-search-params-polyfill';
import axios from 'axios';
import { AsyncStorage } from 'react-native';
import Rx from 'rxjs/Rx';

let _HttpServiceInstance = null;

class HttpService {

  constructor(envStr) {
    console.log('DEFAULT', axios.defaults);
    if(!_HttpServiceInstance){
      this.__proto__.ghtnk = null;
      axios.defaults.baseURL = this.getBaseUrlApi()[envStr || 'DEV'];
      axios.interceptors.response.use(
        (resp) =&gt; {
          let ghresp = resp.data || resp;
          ghresp.status = resp.data ? resp.data.status : resp.status;
          return ghresp;
        },
        (err) =&gt; {
          if( err.status === 401 ){
              this.removeToken();
              // go to login
          }
          return Promise.reject(err);
        }
      )
      _HttpServiceInstance = this;
    }
    return _HttpServiceInstance;
  }

  getBaseUrlApi = () =&gt; {
    return {
      DEV : 'https://dev-api.domainname.com/',
      TEST: 'https://test-api.domainname.com/',
      QA  : 'https://qa-api.domainname.com/',
      LIVE: 'https://api.domainname.com/',
    };
  }

  switchBaseUrlApi(envStr) {
    axios.defaults.baseURL = this.getBaseUrlApi()[envStr];
  }

  getToken = (callback) =&gt; {
      let promise = AsyncStorage.getItem('ghtkn');
      if( callback ){
        promise.then(callback, () =&gt; { console.log('getToken: ', err) });
      }
      else return promise;
  };

  setToken = (token) =&gt; {
    return AsyncStorage.setItem('ghtkn', token);
  };

  removeToken = () =&gt; {
    AsyncStorage.removeItem('ghtkn');
  };

  setAuthHeaders = (callback, noNeedToken) =&gt; {
    if ( noNeedToken ) {
      callback(); return;
    }
    this.getToken(
      (token) =&gt; {
        if (token) {
          axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
          callback();
        }
        else{ console.log('NO TOKEN PRESENT'); }
      },
      (err) =&gt; { console.log('GET TOKEN: ', err); },
    );
  };

  // GET
  get = (url) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders((token) =&gt; {
      axios.get(url).then(
        (data) =&gt; { subject.next(data); },
        (err) =&gt; { console.log('GET: ', err); }
      );
    });
    return subject;
  };

  // POST
  post = (url, payload, noNeedToken) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders(() =&gt; {
      axios.post( url, this.setParams(payload)).then(
        (resp) =&gt; { subject.next(resp); },
        (err) =&gt; {
          console.log('POST ERROR');
          console.log(err.request, Object.keys(err) );
          subject.error(err);
        }
      );
    }, noNeedToken);
    return subject;
  };

  // PUT
  put = (url, payload) =&gt; {
    let subject = new Rx.Subject();
    this.setAuthHeaders((token) =&gt; {
      axios.put( url, this.setParams(payload)).then(
        (resp) =&gt; { subject.next(resp); },
        (err) =&gt; { console.log('PUT: ', err); }
      );
    });
    return subject;
  };

  // LOGIN
  login = (user, pw) =&gt; {
    return this.post('user/authentication', {username: user, password: pw}, true)
               .do((resp) =&gt; { this.setToken(resp.token); })
  };

  setParams = (jsonParams) =&gt; {
    let params = new URLSearchParams();
    for(param in jsonParams){
      if( jsonParams.hasOwnProperty(param) ){
        params.append(param, jsonParams[param]);
      }
    }
    return params;
  };

}

export { HttpService };
</code></pre></div>
<p dir="auto">This is the error I'm getting from the post request, using <strong>login()</strong> function I created using <strong>axios.post()</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6199235/27515013-e266ee1c-5991-11e7-941c-0569390d3b16.png"><img src="https://user-images.githubusercontent.com/6199235/27515013-e266ee1c-5991-11e7-941c-0569390d3b16.png" alt="screen shot 2017-06-24 at 22 32 54" style="max-width: 100%;"></a></p>
<h2 dir="auto">NOTE:</h2>
<ul dir="auto">
<li>
<p dir="auto">I'm using the latest version of Axios <strong>^0.16.2</strong></p>
</li>
<li>
<p dir="auto">My AndroidManifest.xml contains:</p>
</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.SYSTEM_ALERT_WINDOW&quot;/&gt;"><pre class="notranslate"><code class="notranslate">&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
&lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
</code></pre></div>
<ul dir="auto">
<li>The APIs are under VPN, as I wrote all works fine with iOs emulator but doesn't with the Android one.</li>
</ul>