我在nodejs服务器上本地托管了一个POST api服务,我想从我的angualrJS代码访问,但是我在控制台中收到错误 POST http://10.176.1.85:4242/createUser?action=add net :: ERR_CONNECTION_RESET
我的Node js代码是
app.post('/createUser', function(req, res) {
connection.connect(function(err) {
// ... error checks
console.dir(err);
// Query
var request = new sql.Request();
console.dir(request);
console.dir(req.body);
request.query("insert into dbo.Users (username,password,emailId) values ('" + req.body.username + "','" + req.body.password + "','" + req.body.email + "')", function(err, recordset,fields) {
// ... error checks
console.dir(recordset);
res.send(200);
// res.send(err+recordset+fields+req.body.username+req.body.password+req.body.email);
//connection.close();
});
});
});
我的角色代码是
$http({
method: "post",
url: "http://localhost:4242/createUser",
params: {
action: "add"
},
data: {
name: userDetails
}
}).then(function (response) {
return "Done";
}, function(error) {
return q.reject(error.data);
});