call an api in C#

Anjali Agarwal 1,366 Reputation points

I have the following code:

namespace TwilioSendMessages.Controllers
    public class SMSController : ControllerBase
        private readonly IWebHostEnvironment _webHostEnvironment;
        public readonly IConfiguration _configuration;
        private readonly ITwilioRestClient _client;
        public SMSController(IWebHostEnvironment webHostEnvironment, IConfiguration configuration, ITwilioRestClient client)
            _webHostEnvironment = webHostEnvironment;
            _configuration = configuration;
            _client = client;
        public IActionResult SendSMS(SmsMessage model)
            var message = MessageResource.Create(
            to: new PhoneNumber(model.To),
            from: new PhoneNumber(model.From), 
            body: model.Message,
            client: _client); // pass in the custom client
            return Ok("Success");

when I tried to call the api on my local machine like this:


it says the page is not working. I also tried calling the API this way. I get the same message saying the page is not working:


When I run the code directly. This page comes up:

User's image

When I run the code directly.This page comes up and I can type "To" , "From" and "Message" and it works. How can I call this API using the URL on my local machine.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,146 questions
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
293 questions
0 comments No comments
{count} votes

Accepted answer
  1. JasonPan - MSFT 4,201 Reputation points Microsoft Vendor

    Hi @Anjali Agarwal,

    It's a post request. We can't make it works in browser. If you want to test it in web page, you have to create a html, and invoke this SendSMS function in javascript by using post method.

    Another choice, you can use the tools like Postman to test your api.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful