Pick up json from Postman and play on an object

Asked

Viewed 850 times

-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

inserir a descrição da imagem aqui

  • Put the code Postman generates to better understand what is happening.

  • @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.

  • The breakpoint is being hit there in the Controller, in the Unsubscribe method?

  • Add the Postman screen print to see how it is

  • How you are sending this request to the controller?

  • @Tony, I’ve put the Postman image in the edit

  • 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?

  • Decorates the controller with [Produces("application/json")] and please add the request you are making in the post to the route TesteClient/Unsubscribe. Another point checks whether the Postman request is set to "POST" and "Body" set to JSON(application/json).

  • 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?

Show 4 more comments

1 answer

0

Solved:

My json was wrong, it missed a comma after the email. I just thought it was strange that Postman didn’t scream, it went smoothly. I thought about everything but Postman, because he spun and I thought he was correct. I didn’t notice the red "X" in him.

A friend told me so: "When you try everything and find no solution, it is because the problem is bullshit, usually lack of attention".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.