I am new to cordova and am creating a project in visual studio 2015 to test sending and receiving data in JSON format, I run the codes below in Android Emulator in Visual Studio 2015 and expect the Node.js server to show email and password, but I get an error Failed to load resource: net::ERR_CONNECTION_REFUSED.
I put this code in the onDeviceReady block in index.js:
$.post("http://127.0.0.1:3000/", { email: "test@test.com", password: "123456" },
function (data, status) {
console.log(status);
});
and meta tag in index.html:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://127.0.0.1:3000/">
Node.js server file:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.post('/', function (req, res) {
var email = req.body.email;
var pass = req.body.password;
res.setHeader('Access-Control-Allow-Origin', '*');
console.log(email + ", " + pass);
res.statusCode = 200;
res.end();
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
What is the problem?
Update:
I am running the project on my mobile device and the problem is resolved! but some points to keep in mind: 1. I am changing the IP address to my real IP server! 2. When I use a domain instead of an IP address, an error is displayed Failed to load resource: net::ERR_NAME_NOT_RESOLVED!
:
Failed to load resource: net::ERR_CONNECTION_REFUSED Android. ?
2. domain Failed to load resource: net::ERR_NAME_NOT_RESOLVED. ?