0

This is POST method Request Body ,where I am trying to send special characters but I am getting error.

                {
  
                     "name": "@!#%^#)(?><%$"*",
     
                      "description": "string",

                }

ERROR :

{

"errors":

{

"name": [ "After parsing a value an unexpected character was encountered: *. Path 'name', line 2, position 14."

]

},

"title": "One or more validation errors occurred.",

"status": 400,

}

//This is my Get Method

[HttpGet]

public async Task<IActionResult> GetByNameAsync( [FromQuery] string name)
{
_service.GetByName(name)
 return Ok();
}
Ajit
  • 29
  • 6

1 Answers1

0

Since your name contains double quotes, you need to add \ before your ".

You can try the following Json:

{
"name": "@!#%^#)(?><%$\"*",
"description": "string"
}

Please use objects to receive parameters in the background.

Class:

public class Model
{
    public string name { get; set; }
    public string description { get; set; }
}

Post action:

[HttpPost]
public IActionResult Test([FromBody]Model model)
{   
  //...
  return Ok();
}

Result: enter image description here

Yinqiu
  • 6,609
  • 1
  • 6
  • 14