Home:ALL Converter>ionic POST request error, net::ERR_CONNECTION_REFUSED

ionic POST request error, net::ERR_CONNECTION_REFUSED

Ask Time:2017-03-31T06:48:18         Author:lys916

Json Formatter

i have an ionic app and i'm trying to test it on my android device. the app works when testing it on the browser using 'ionic serve' but when i run 'ionic run android' the post request does not seem to hit the server. I'm getting an error

'POST http://localhost:3000/login net::ERR_CONNECTION_REFUSED'

for the server i'm using nodejs and have access-control..

app.use(function (req, res, next) {
  res.header('Access-Control-Allow-Credentials', true);
  res.header('Access-Control-Allow-Origin', req.headers.origin);
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.header(
    'Access-Control-Allow-Headers', 
    'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'
  );
  if ('OPTIONS' === req.method) {
    res.status(200).end();
  } else {
    next();
  }
});

i've also installed cordova whitelist plugin and the meta content-security-policy like so..

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src *    'unsafe-inline'; script-src * 'unsafe-inline'; media-src *; img-src * data:;"/>

but i'm still getting the same error. i've also tried using my ip instead of localhost and got this error.

OPTIONS http://192.168.1.66:3000/login net::ERR_CONNECTION_TIMED_OUT

i've followed this thread.. net::ERR_CONNECTION_REFUSED ionic suggesting that i enable CORS by installing the microsoft.aspnet.webapi.cors.. i followed this link https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Cors and now i'm totally lost. please help, i've been on this for 3 days now. i appreciate all your help. thank you.

Author:lys916,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43129604/ionic-post-request-error-neterr-connection-refused
yy