.NET 6 Web API接口接收含#的userId参数时内容截断问题咨询
.NET 6 Web API接口接收含#的userId参数时内容截断问题咨询
我有一个基于.NET 6.0的Web API项目,最近在传递字符串参数时遇到了问题。
我的接口定义如下:
[HttpGet("contact/{userId}")] public async Task<ActionResult<string>> GetUserAsync(string userId) { var user = await _userService.GetUserAsync(userId); return user is null ? NotFound() : Ok(user); }
当我传入带#的userId(比如example-id-#1)时,接口接收到的内容会被截断,只拿到example-id-;但如果传入不含#的字符串,就能完整接收。
我想请教两个问题:
- 为什么Web API会截断这个参数值?
- 如何在不修改传入值的前提下解决这个问题?
感谢解答!
备注:内容来源于stack exchange,提问作者0Neji
相关产品推荐
相关产品推荐

