-1
Have POST and use the Postman to test. Mount the url and body in Postman. Now, when I test on my object on mine Controller comes NULL, and of course it’s because I didn’t do it correctly. What do I have to do? Controller
[Route("api/[controller]")]
public class OptoutClientController : Controller
{
HttpClient client = new HttpClient();
[HttpPost]
public IActionResult Unsubscribe([FromBody]OptOutCliente cliente)
{
return Ok();
}
}
Model
public class OptOutCliente
{
public Int64 Cpf { get; set; }
public String Email { get; set; }
public String Telefone { get; set; }
public String Bandeira { get; set; }
public String Canal { get; set; }
}
Body do Postman
{
"Cpf": "128907",
"Email": "[email protected]"
"Telefone": "971418418",
"Bandeira": "CB",
"Canal": "EML"
}
How do I get this json from the gold side in my controller?
EDIT1
Postman
Put the code Postman generates to better understand what is happening.
– Maycon F. Castro
@What do you mean, Mayconf.Castro? I don’t understand. When I break into Controller, I have nothing, but I think it’s because something else is missing and I don’t know what it is.
– pnet
The breakpoint is being hit there in the Controller, in the Unsubscribe method?
– Tony
Add the Postman screen print to see how it is
– Tony
How you are sending this request to the controller?
– Marconi
@Tony, I’ve put the Postman image in the edit
– pnet
Body’s content needs to be the json specified in the question and the URL would end in
/Unsubscribe
. That’s why you’re giving null?– Tony
Decorates the controller with
[Produces("application/json")]
and please add the request you are making in the post to the routeTesteClient/Unsubscribe
. Another point checks whether the Postman request is set to "POST" and "Body" set to JSON(application/json).– davidterra
The client variable comes null and I’m forgetting something, I know it and I don’t know what it is. The way it is, client should or should not be NULL?
– pnet