【发布时间】:2021-12-03 20:00:47
【问题描述】:
在 web 服务中进行以下 Post 调用。
try{
User = await _service.Post<User>("api/authenticate", model);
}
catch(Exception ex){
Console.Writeline($"exception{ex.Message}");
}
在控制器中,如果用户名或密码错误,将导致未经授权。
return Unauthorized(new{message = "PW wrong"})
或用户对象
return Ok(user);
该服务能够捕获一个
return BadRequest();
响应但不是未经授权的响应。
我想知道这些响应之间是否存在差异。
我已经尝试在StackOverFlow question的这个答案中使用 System.Net.WebException
提前致谢
【问题讨论】:
-
Http 错误代码不会抛出异常你可能想通过这个:stackoverflow.com/questions/21097730/…
-
这很奇怪,因为当我返回 badrequest 时它会被捕获
标签: asp.net-core asp.net-web-api blazor-server-side blazor-webassembly asp.net-blazor