Base solution for your next web application
Open Closed

SimpleTaskSystem Http Get : Your request is not valid #604


User avatar
0
keepfool created

I am trying the SimpleTaskSystem, when I use ajax get to get all tasks, I got an error: Your request is not valid! Here is the steps I have done.

  1. Download the source code of SimpleTaskSystem from github.
  2. Restore referenced packages through Nuget.
  3. Change the ITaskApplicationService
public interface ITaskAppService : IApplicationService
    {
       [HttpGet]
        GetTasksOutput GetTasks(GetTasksInput input);

        [HttpPut]
        void UpdateTask(UpdateTaskInput input);

        [HttpPost]
        void CreateTask(CreateTaskInput input);
    }
  1. I want to show all the tasks by http get method, the rerequest uri is <a class="postlink" href="http://localhost:6247/api/services/tasksystem/task/GetTasks">http://localhost:6247/api/services/task ... k/GetTasks</a>. Then I got this error at the home page: Your request is not valid! But if I change the ITaskApplicationService as below, I can successfully get the tasks.
public interface ITaskAppService : IApplicationService
    {
        [HttpPost]
        GetTasksOutput GetTasks(GetTasksInput input);

        [HttpPut]
        void UpdateTask(UpdateTaskInput input);

        [HttpPost]
        void CreateTask(CreateTaskInput input);
    }

How can I get tasks with http get?


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    This is related to working of ASP.NET Web API.

    Get only supports primitive parameters by default, not complex types (like GetTasksInput). To make it work, you can change method signature like:

    [HttpGet]
    GetTasksOutput GetTasks([FromUri] GetTasksInput input);
    

    See <a class="postlink" href="http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api">http://www.asp.net/web-api/overview/for ... et-web-api</a> for more