프런트 엔드를 백엔드의 엔드 포인트에 연결하려고하지만 항상 400 : Bad Request 응답을 받고 있는데 그 이유를 모르겠습니다. 이미 Swagger에서 동일한 이메일 값으로 엔드 포인트를 테스트했으며 완벽하게 작동했습니다. 수신 한 이메일이 유효한 이메일이고 유형이 문자열인지 확인할 수도 있습니다. 연결되지 않는 이유는 무엇입니까?
resetPassword(email: String): Observable<any> {
console.log("Type:" ,typeof(email));
console.log("THE RECEIVED EMAIL IS: ", email);
return this.http.post<any>(
endpoint + 'User/ForgetPassword',
JSON.stringify(email),
httpOptions
);
}
[AllowAnonymous]
[HttpPost("ForgetPassword")]
public IActionResult ForgetPassword([FromBody]ForgetCredencialModel model)
{
try
{
var newPassword = _userService.GenerateRandomPassword();
var user = _userService.UpdateCredentials(model.Email, newPassword);
_emailService.ForgetCredencialsEmail(user.Username, newPassword, model.Email);
return Ok(new { Message = "New Password in the email !" });
}
catch (AppException ex)
{
// return error message if there was an exception
return BadRequest(new { message = ex.Message });
}
}
public class ForgetCredencialModel
{
public string Email { get; set; }
}
그것은해야한다
JSON.stringify({Email: email}));
당신의 행동은 몸을 기대하기 때문에
{ "Email": "your@email" }
ForgetCredencialModel
다른 속성 으로 확장 할 계획이 없다면 단순화하고 다음을 사용하십시오 JSON.stringify(email)
.
public IActionResult ForgetPassword([FromBody]string email)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다