我正试图将changePasswordDto传递给RestApi,我创建了第二个Put请求
[HttpPut("updatePassword")]
public ActionResult<User> Put([FromBody] ChangePasswordDto newPass)
{
return Ok("Hi Boy");
}
从角度看是这样的:
changePassword(newPass: string) {
this.currentUserId = this.authService.getUserID();
this.changePasswordDto = {
newPW: newPass,
userId: this.currentUserId
}
return this.http.put<any>(environment.apiURL + '/api/user/updatePassword', this.changePasswordDto);
}
我给restApi设置了一个断点,但它没有到达那里。当我为邮递员办理登机手续时,一切都很好,https://localhost:44375/api/user/updatePassword工作并在控制器中命中断点。为什么它不从角度进入api。感谢
这是因为http.put
返回了一个Observable,它只有在.subscribe
给它时才会被执行。
this.http.put<any>(environment.apiURL + '/api/user/updatePassword', this.changePasswordDto)
.subscribe(response => /* do something here */ );