简体   繁体   English

ASP.NET Core 3.1 http 标头中的 ñ 字符

[英]ñ character in ASP.NET Core 3.1 http header

I have a ASP.NET Core 3.1 web server and I'm receiving post requests like this:我有一个 ASP.NET Core 3.1 Web 服务器,我正在接收这样的发布请求:

[HttpPost("/api/loginweb")]
        public IActionResult loginWeb([FromHeader(Name = "usuario")] String usuario, [FromHeader(Name = "pass")] String pass)
        {

The problem I have is sending the ñ character on a header:我遇到的问题是在标题上发送 ñ 字符:

在此处输入图片说明

But, when I receive it I get:但是,当我收到它时,我得到:

在此处输入图片说明

You can right-click barñfoo in postman, choose EncodeURlComponent option, and then when the data of usuario is received, use HttpUtility.UrlDecode() method to get the string containing special characters.你可以right-click在邮递员barñfoo,选择EncodeURlComponent选项,然后的数据时usuario被接收,使用HttpUtility.UrlDecode()方法来获取包含特殊字符的字符串。

 [HttpPost("/api/loginweb")]
        public IActionResult loginWeb([FromHeader(Name = "usuario")] string usuario, [FromHeader(Name = "pass")] string pass)
        {
            usuario = HttpUtility.UrlDecode(usuario);
            return Ok();
        }

Here is the process to test:下面是测试过程:

在此处输入图片说明

Update更新

I have found a thread which explains the reason of this phenomena.我找到了一个线程来解释这种现象的原因。 You can have a look for this你可以看看这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM