Click here to Skip to main content
16,015,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm not looking for code, more so just guidance. So far, I have a very basic WebAPI with only a post function. My goal is to load up a console application that uses HttpClient to send a POST message to my WebAPI. I've looked into videos on how to do this, but it all seems quite complicated and was wondering if anyone could simplify the concepts for me.

What I have tried:

This is my very basic API that only has one post method that's empty:
namespace WebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class GeneratorStatusController : ControllerBase
    {
        public GeneratorStatusController()
        {

        }

        [HttpPost]
        public async bool PostGeneratorStatus(bool powerIsOn)
        {
            // return true/false depending on powerIsOn
        }
    }
}
Posted
Updated 23-Sep-20 5:37am

1 solution

Have a read of this

Call a Web API From a .NET Client (C#) - ASP.NET 4.x | Microsoft Docs[^]

if you google "use httpclient to call web api" you'll find lots of other examples to look at.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900