title: ionic: http post request works in browser but not in mobile
body: <p>I am calling a simple authentication API in my application using <code>$http.post</code>. </p>
  
  <pre><code> this.login = function(scope, credentials) {
       var url = REST_API.DOMAIN + REST_API.LOGIN;
       $http.post(url, $.param(credentials)/* convert from json to query string */, {
           headers: {
               'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
           }
       })
       .success (function(response){
           $log.info(response);
       })
       .error(function(data, status, header, config){
            $log.error(data);
       });
  }
  </code></pre>
  
  <p>My code works seamlessly when I test it in browser using the following command:</p>
  
  <blockquote>
    <p>ionic serve</p>
  </blockquote>
  
  <p>But when I launch it in my phone:</p>
  
  <blockquote>
    <p>ionic run -lc android</p>
  </blockquote>
  
  <p>The error callback function is called immediately with response data being null:</p>
  
  <p><a href="https://i.stack.imgur.com/P7EXi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P7EXi.png" alt="enter image description here"></a></p>
  
  <p>This piece of code used to work but at some point in time it's stopped working. The only thing I remember doing that could have affected this behavior is installing newer version of android:</p>
  
  <blockquote>
    <p>cordova platform remove android<br>
    cordova platform add android@5.1.1</p>
  </blockquote>
  
  <p>Another point that I've noticed: I am sending the http request to a web service on localhost. But if I host the webservice code on a remote server the http request will work successfully on my phone. </p>