我有 Angular2 服务
logIn (username, password): Observable<User[]> {
return this.http.get(this.getUserUrl + username + '/' + password)
.map(this.extractData)
.catch(this.handleError);
}
向
发送请求router.get('/authenticate/:username/:password', function(req, res, next) {
schema.User.find({ username: req.param("username"), password: req.param("password")}).exec(function (err, users) {
if (err)
return console.error(err);
console.log("Load success: ", users);
res.send(users);
});
});
但我需要一种方法来发送用户名
,尤其是密码
,并且不会将其暴露给请求本身
最佳答案
您可以更改发帖方式
logIn (username, password): Observable<User[]> {
return this.http.post(this.getUserUrl + "test", {username: username, password: password})
.map(this.extractData)
.catch(this.handleError);
}
Node :
router.post('/authenticate/test', function(req, res, next) {
var username = req.body.username;
var password = req.body.password;
schema.User.find({ username: username, password: password }).exec(function (err, users) {
if (err)
return console.error(err);
console.log("Load success: ", users);
res.send(users);
});
});
关于node.js - 从 angular2 服务发送正文中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43322210/