http从angularangular色向node.js服务器发送密码

这正在扰乱我。 我知道我可以做到以下几点:

$http.post('https://url:8080/api/registerUser?username=' + usrName + '&usrPassword=' + usrPassword); 

但我猜这不是传递密码到服务器的正确方法。 所以我试过这个:

 $http({ method: 'POST', url: url2, data: { userName: encodeURIComponent(usrName), userPassword: encodeURIComponent(usrPassword) }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); 

但是当我收到它的时候,我无法在node.js中的任何地方find数据。 我在这里做错了什么?

你可以find:

  • req.bodyreq.body数据
  • req.query上获取参数
  • req.params参数

req.body.userName为你的例子