我有我的控制器类 asnamespace air_bnb.Controllers{ [Route(\'api/[controller]\')] public class UserController : Controller { private readonly UserDbContext con...
我的控制器类为
namespace air_bnb.Controllers
{
[Route("api/[controller]")]
public class UserController : Controller
{
private readonly UserDbContext context;
private readonly IConfiguration _config;
public UserController(IConfiguration configuration, UserDbContext _context)
{
_config = configuration;
context = _context;
}
[HttpPost("register")]
public async Task<IActionResult> Register(LoginReqDto request)
{
System.Diagnostics.Debug.WriteLine(request.Password);
var hashedPw = BCrypt.Net.BCrypt.HashPassword(request.Password);
User createdUser = new User
{
Email = request.Email,
Password = hashedPw,
Id = Guid.NewGuid().ToString()
};
createdUser.Email = request.Email;
createdUser.Password = hashedPw;
await context.Users.AddAsync(createdUser);
try
{
await context.SaveChangesAsync();
}
catch (Exception e)
{
return BadRequest(request.Password);
}
return Ok(request.Password);
}
}
}
从前端来说,我使用的 HTTPClient
是 Angular。当我使用 Postman 发送数据时,一切都运行正常。
ASP.NET api 将请求主体设为 null
下载声明:
本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!