Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ben 6 posts 96 karma points
    Feb 16, 2020 @ 18:16
    Ben
    0

    UmbracoApiController 404 error when posting body with request, works fine without body

    Hi,

    I've managed to get a HttpPost call working from a javascript application, however the moment I add pararmeters to the method and fetch request it always returns a failed response.

    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using System.Web.Script.Serialization;
    using Umbraco.Core;
    using Umbraco.Core.Composing;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    using Umbraco.Web.WebApi;
    using System.Web.Http;
    
    public class CardListController : UmbracoApiController
    {
      public CardListController(){};
     [System.Web.Http.HttpPost]
     public JsonResult LoadMoreCards([FromBody]string page)
        {
           ....
        }
    

    In my javascript code:

        const data = { page: '0' };
        fetch(
          `https://localhost:44378/umbraco/api/cardlist/loadmorecards/`,
          {
            method: 'POST',
            headers: {
                'Content-Type': "application/json;",
            },
            body: JSON.stringify(data) 
          }
        )
    

    Can anyone see where this could be going wrong?

Please Sign in or register to post replies

Write your reply to:

Draft