这是我在AuthController中的注册方法。
[HttpPost(ApiRoutes.Auth.Register)]
public async Task<IActionResult> Register(UserRegistrationRequest request)
{
var authResponse = await _authService.RegisterAsync(request.Email, request.Password);
if (!authResponse.Success)
{
return BadRequest(new AuthFailedResponse
{
Errors = authResponse.Errors
});
}
return Ok(new AuthSuccessResponse
{
Token = authResponse.Token,
RefreshToken = authResponse.RefreshToken
});
}
我试图通过以下方式调用此方法
TestClient.PostAsync()
方法,不幸的是,它总是返回Bad Request。我已经试着打电话给
TestClient.PostAsJsonAsync(ApiRoutes.Auth.Register, user)
方法通过导入
Microsoft.AspNet.WebApi.Client
包,结果是一样的。
var user = new UserRegistrationRequest
{
Email = "user1@testtest.com",
Password = "P@ssw0rd1!!!!!"
};
var response = await TestClient.PostAsync(
ApiRoutes.Auth.Register,
new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8)
{
Headers = { ContentType = new MediaTypeHeaderValue("application/json") }
});