首页 > 解决方案 > 角度 PUT 请求未达到快速代码

问题描述

我的 app.js 后端完美地满足了我的需求。Postman 在测试时正确更新,但由于某种原因,角度 http PUT 请求未连接。我真的不知道为什么,因为路径是一样的。任何帮助表示赞赏。

错误: "Http failure response for http://localhost:3000/api/user/email/5dc1b5bccghdc22788b30922: 0 Unknown Error"

角服务


   const updateEmail: UserEmailChange = {
     id: id, oldEmail: oldEmail, newEmail: newEmail
   };

   return this.http.put('http://localhost:3000/api/user/email/' + updateEmail.id, updateEmail, { headers: { 'Content-Type': 'application/json' } });

 }

应用程序.js

app.put('/api/user/email/:id', (req, res) =>
User.update(
  {email: req.body.oldEmail},
  {email: req.body.newEmail}
  ).then( user => {
  console.log(user);
  res.json(user);
  // res.sendStatus(200);
  })


.then( user => {
console.log(user);
res.json(user);
// res.sendStatus(200);
}).catch(err => console.log(err)));

标签: angular

解决方案


您应该将 :id 替换为服务中的值。


推荐阅读