What is the reason to unable to call/invoke my asp.net core 6 api?

mehmood tekfirst 771 Reputation points
2022-04-14T06:58:38.923+00:00

I have created one rest api in asp.net mvc core 6 but this is not being invoked through postman or even from browser.

This is my service.

	[ApiController]  
    [Route("api/[controller]")]  
    public class RentalController : ControllerBase  
    {  
        private readonly IGMManager _gmManager;  
  
        private static readonly string[] Summaries = new[]  
        {  
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"  
        };  
  
        private readonly ILogger<CarRentalController> _logger;  
  
        public RentalController(ILogger<CarRentalController> logger)  
        {  
            _logger = logger;  
            _gmManager = new GMManager();  
        }  
  
  
        [HttpGet("inquiries")]  
        public async Task<ActionResult<List<WebInquiry>>> Inquiries()  
        {  
           List<WebInquiry> items =  await Task.Run(() =>  
            {  
                List<WebInquiry> items = _gmManager.WebInquiry(null);  
                return items;  
  
            });  
            return items;  
        }        
    }  
}  

and I am trying to invoke it as mentioned below

https://localhost:7260/api/inquiries  

I am receiving such responses

192996-image.png

and this is the dotnet cli build response when I executed the application.

info: Microsoft.Hosting.Lifetime[14]  
      Now listening on: https://localhost:7260  
info: Microsoft.Hosting.Lifetime[14]  
      Now listening on: http://localhost:5260  
info: Microsoft.Hosting.Lifetime[0]  
      Application started. Press Ctrl+C to shut down.  
info: Microsoft.Hosting.Lifetime[0]  
      Hosting environment: Development  
info: Microsoft.Hosting.Lifetime[0]  
Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-04-14T07:37:56.047+00:00

    Hi @mehmood tekfirst

    [ApiController]    
    
     [Route("api/[controller]")]  
     public class RentalController : ControllerBase  
     {  
          ...  
         [HttpGet("inquiries")]  
         public async Task<ActionResult<List<WebInquiry>>> Inquiries()  
         {  
    

    Since you are using [HttpGet("inquiries")], the request URL should be https://localhost:7260/api/Rental/inquiries.

    More detail information, see Route templates.

    If the above request URL still not working, can you share the program.cs file content?


    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,
    Dillion

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.