ñ 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:

[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:

enter image description here

But, when I receive it I get:

enter image description here

Upvotes: 1

Views: 889

Answers (1)

LouraQ
LouraQ

Reputation: 6881

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.

 [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:

enter image description here

Update

I have found a thread which explains the reason of this phenomena. You can have a look for this

Upvotes: 1

Related Questions