I am trying to create a basic API service in ASP.Net Core 3.1.
Before going to the problem description, I have already gone through these questions-
- Post parameter is always null
- Asp.net Core Post parameter is always null
- ASP.NET Core API POST parameter is always null
- Web Api Parameter always null
- web-api POST body object always null
but, none of fixing my issue.
What I am trying to do is create a basic API which will take a string
from the API then use the string
and give a response based on the string. What I am doing is like this in Controller
-
[Route("/")]
[ApiController]
[EnableCors]
public class XmlValidatorController : ControllerBase
{
........................
........................
[HttpPost("verify_string")]
public ActionResult<ICollection<Certificate>> VerifyXmlString([FromQuery(Name = "xml")] string xml)
//string xml => Giving Null
//[FromQuery(Name = "xml")] string xml => Giving Null
//[FromBody] string xml => Unsupported Media Type - 415
//[FromBody] dynamic xml => Unsupported Media Type - 415
//HttpRequestMessage msg => Unsupported Media Type - 415
{
...............
...............
}
If I am creating a POST
request from POST Man
, I am creating like this-
and
In my controller, if I am putting a debugging pointer, I am getting this-
So, I am always getting null
in POST
request.
If I use others in the function parameter, I am getting this errors-
- string xml => Giving Null
- [FromQuery(Name = "xml")] string xml => Giving Null
- [FromQuery(Name = "xml")] string xml => Giving Null
- [FromBody] string xml => Unsupported Media Type - 415
- [FromBody] dynamic xml => Unsupported Media Type - 415
- HttpRequestMessage msg => Unsupported Media Type - 415
Can anyone please help me find the parameter string from the Controller action paramenter/ function parameter (XML).
Re-
I haven't tried with creating a model for the request because I think it will make the code a little more complex and that become overkill as I need just a string.
Re-re-
My Startup.cs
file has no special configuration, it is default code provided during code creation. The code for the file can be found in here. And code for controller can be found in here.
Complete Codebase can be found in this Github Repo.
Thanks in advance for helping.