Post Method is not running on Postman

0

Creating a POST method and testing for Postman , I can not access the Controller of this POST . I did not implement a lot yet, but I should stop at Break if, of course, it was working. Controller

[Route("api/[controller]")]
public class OptOutClientController : Controller
{
    private IOptOutCreateService optOutCreateService;

    HttpClient httpClient = new HttpClient();

    public OptOutClientController(IOptOutCreateService optOutCreateService)
    {
        this.optOutCreateService = optOutCreateService;
    }

    [HttpPost]
    public async Task<IActionResult> OptOutPostClient([FromBody]OptOutRequest client)
    { **Breakpoint nessa chave e não entra **

        if (client == null)                                                                                          
            throw new OptOutException( "Favor informar os dados do OptOut!");

        var result = await optOutCreateService.Process(new OptOutCreateCommand(client.Cpf, client.Email, client.Telefone, client.Bandeira, client.Canal));

        return Ok(new ApiReturnItem<OptOutResult> { Item = result, Success = true });
    }
}

Postman Screenshot running POST

EDIT1

Imadeasmallexamplewithnothing,justacontrollerandnothingelseandIhavethesameerror:Startup.cs

publicclassStartup{publicvoidConfigureServices(IServiceCollectionservices){services.AddMvc();services.AddRouting();}//Thismethodgetscalledbytheruntime.UsethismethodtoconfiguretheHTTPrequestpipeline.publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){app.UseMvc(routes=>{routes.MapRoute(name:"default",
                    template: "{controller=Home}/{action=Index}");
            });
        }
    }

controller

[Route("api/[controller]")]
    public class HomeController : Controller
    {
        [HttpPost]
        public IActionResult postar()
        {
            return Ok();
        }
    }

Postman url: link body: {"test": "1"}

And I get the same error as page not found

    
asked by anonymous 20.06.2018 / 16:12

1 answer

1

Explanation

You assigned a path to Controller but did not assign it to Action , in which case the Conventional Routing . In this type of routing, the Action name for route construction is used by default.

In your case, you are not inserting the portion of the route responsible for directing Action ( OptOutPostClient )

Solution

Change the POST by directing to the route below:

http://localhost:51585/api/OptOutClient/OptOutPostClient

If you do not have a default route applied, put it as follows:

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}");
        });
    
20.06.2018 / 16:25