locked
Unable to Post and Put via Postman RRS feed

  • Question

  • User-309523270 posted

    Hi,

    I'm trying to do an HttpPost and HttpPut in the Web-Api via Postman.

    It's returning a Response code: 404.  It's  adding a request(shown above the method name) but it doesn't go into the method body when I execute on debug mode.  No record is inserted either. 

    Here's the script:

    CodeTableController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using myCMS.Business;
    using myCMS.Business.Repository;
    using Common;
    using Common.DTOs;
    using Common.Models ;
    using AutoMapper;
    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json;
    //using System.Web.Http;

    namespace myCMSNet.WebApi.Controllers
    {

            [Route("api/[controller]")]
            public class CodeTableController : Controller
        {
            private readonly CodeTableRepository _CodeTableRepository;
            private readonly IMapper _mapper;

            public CodeTableController(CodeTableRepository aCodeTableRepository, IMapper mapper)
            {
                _CodeTableRepository = aCodeTableRepository;
                _mapper = mapper;
            }


            // GET: api/values
            [HttpGet]
            public IEnumerable<string> Get()
            {
                return new string[] { "value1", "value2" };
            }


            [HttpGet("{asCategory}/{asCode}")]
            public async Task<CodeTableAddVM> Get(string asCategory, string asCode)
            {
                return await _CodeTableRepository.FindById(asCategory, asCode);
            }


            [HttpPost]
            public async Task<IActionResult> create(CodeTableAddVM oData)
            {
                var res = await _CodeTableRepository.Create(oData);

                if (res == null)
                {
                    return BadRequest();
                }
                return Ok(res);
            }


            [HttpPut]
            public async Task<IActionResult> Put([FromBody] CodeTableAddVM oData)
            {
                if (ModelState.IsValid)
                {
                    var result = await _CodeTableRepository.Update(oData.Category, oData.Code, oData);
                    if (result == null)
                        return BadRequest();

                    return Ok(result);
                }
                return BadRequest();
            }
        }
    }

    Postman:

    POST
    http://localhost:54277/api/CodeTable/create

    Header
    Content-Type  :  application/json

    Body:  raw    JSON(application/json)
    {
    "category" : "victim_category",
    "code" : "TEST",
    "value" : "TEST TEST TEST",
    "created_dt" : "3/12/2018",
    "created_by" : "1",
    "modified_dt" : "3/12/2018",
    "modified_by" : "1"
    }

    Please advise.

    Thanks,

    tinac99

    Monday, March 12, 2018 9:47 PM

Answers

  • User-309523270 posted

    I got it...I had the wrong URL

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 13, 2018 12:12 AM