WebApi HTTPPOST Endpoint not being hit

后端 未结 1 381
梦如初夏
梦如初夏 2021-01-17 00:31

I have the following simple HTTPPOST endpoint;

[AllowAnonymous]
[HttpPost]
[Route(\"forgotPassword\")]
public IHttpActionResult ForgotPassword(string userNam         


        
相关标签:
1条回答
  • 2021-01-17 01:17

    If you want to send mulitple parameters when doing a post request you should create a DTO that contains the parameters as

    public class forgetPasswordDTO
    {
        public string userName { get; set; }
        public string callbackUrl { get; set; }
    }
    

    Then add the DTO as a method parameter with the [FromBody]

    [AllowAnonymous]
    [HttpPost]
    [Route("forgotPassword")]
    public IHttpActionResult ForgotPassword([FromBody] forgetPasswordDTO data)
    

    And in you client, create the object as

    var data = {
        'userName': user,
        'callbackUrl': url
    };
    

    And add it to the body of the request.

    Here's a nice article about this topic

    0 讨论(0)
提交回复
热议问题