Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to invoke POST method by adding [FromBody] attribute in Postman tool

How to invoke POST method by adding [FromBody] attribute in Postman tool

Scheduled Pinned Locked Moved ASP.NET
jsonhelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meeram39
    wrote on last edited by
    #1

    I have a POST method with [FromBody] attribute. I tried to call the same from PostMan. But everytime Postman gives 404 error. The Web Api is not hitting at all. Following is my source code:

    [HttpPost]
    [Route("api/CustomerService")]
    public HttpResponseMessage GetServiceChats([FromBody]string to, string from)
    { }

    What I have done is, I added the parameters by Selecting Body-->raw-->JSON options and type the parameters as below:

    {
    "to" : "919191919191",
    "from" : "90909090900"
    }

    What could be the probable reason? If the same I attached in URL without the FromBody attribute, it works. Please provide any suggestions.

    Richard DeemingR 1 Reply Last reply
    0
    • M meeram39

      I have a POST method with [FromBody] attribute. I tried to call the same from PostMan. But everytime Postman gives 404 error. The Web Api is not hitting at all. Following is my source code:

      [HttpPost]
      [Route("api/CustomerService")]
      public HttpResponseMessage GetServiceChats([FromBody]string to, string from)
      { }

      What I have done is, I added the parameters by Selecting Body-->raw-->JSON options and type the parameters as below:

      {
      "to" : "919191919191",
      "from" : "90909090900"
      }

      What could be the probable reason? If the same I attached in URL without the FromBody attribute, it works. Please provide any suggestions.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The [FromBody] attribute is used to read a single simple value from the request body: Parameter Binding in ASP.NET Web API - ASP.NET 4.x | Microsoft Docs[^] Given your signature, the from parameter needs to be a query-string parameter, and the request body needs to be simply:

      "90909090900"

      If you want the API to match the request you've shown, use a model to represent the parameters:

      public class ServiceChatsModel
      {
      public string To { get; set; }
      public string From { get; set; }
      }

      [HttpPost]
      [Route("api/CustomerService")]
      public HttpResponseMessage GetServiceChats(ServiceChatsModel model)
      {
      ...


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M S 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        The [FromBody] attribute is used to read a single simple value from the request body: Parameter Binding in ASP.NET Web API - ASP.NET 4.x | Microsoft Docs[^] Given your signature, the from parameter needs to be a query-string parameter, and the request body needs to be simply:

        "90909090900"

        If you want the API to match the request you've shown, use a model to represent the parameters:

        public class ServiceChatsModel
        {
        public string To { get; set; }
        public string From { get; set; }
        }

        [HttpPost]
        [Route("api/CustomerService")]
        public HttpResponseMessage GetServiceChats(ServiceChatsModel model)
        {
        ...


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        meeram39
        wrote on last edited by
        #3

        Yes. Thank you Richard. I have done that in the meanwhile,and got it worked.Thank you. Worked both in Postman and Fiddler.:thumbsup:

        1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          The [FromBody] attribute is used to read a single simple value from the request body: Parameter Binding in ASP.NET Web API - ASP.NET 4.x | Microsoft Docs[^] Given your signature, the from parameter needs to be a query-string parameter, and the request body needs to be simply:

          "90909090900"

          If you want the API to match the request you've shown, use a model to represent the parameters:

          public class ServiceChatsModel
          {
          public string To { get; set; }
          public string From { get; set; }
          }

          [HttpPost]
          [Route("api/CustomerService")]
          public HttpResponseMessage GetServiceChats(ServiceChatsModel model)
          {
          ...


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          S Offline
          S Offline
          Stefanie Eberhardt
          wrote on last edited by
          #4

          Thanks

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups