1

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

Carlos López Marí
  • 1,432
  • 3
  • 18
  • 45

1 Answers1

1

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

LouraQ
  • 6,443
  • 2
  • 6
  • 16
  • Well, yes, I finnally encoded it on the client side as in my case it depends on me, but I didn't want to do that, I just want to be able to make the API understand the encoding, like in any other languges and frameworks... I see your answer like a workaround. Maybe it is imposible and your approach is the best one... – Carlos López Marí Oct 05 '20 at 06:20
  • 1
    @CarlosLópezMarí,Sorry, this is the solution I have found so far. If allowed, putting it in the body rather than header and passing it will not cause this issue. – LouraQ Oct 06 '20 at 09:01
  • 1
    @CarlosLópezMarí ,I have updated my reply, you could refer it, if it helped you ,please accept as the answer. – LouraQ Oct 20 '20 at 08:11