I am learning ASP.NET Core. The server I am using for this purpose is Postman, which I import a JSON file to from disc. The code for the API is written in Visual Studio and is compiled error-free. When I send a GET request in Postman, I get this error: "Could not get any response". To solve this I made changes in the setting (see the attached images), but it was not the solution. Could you please me with this?
This is an screenshot showing the GET request and the error I get:
The code for the Controller:
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CityInfo.API.Controllers
{
[Route("api/cities")]
public class CitiesController : Controller
{
[HttpGet()]
public IActionResult GetCities()
{
return Ok(CitiesDataStore.Current.Cities);
}
[HttpGet("{id}")]
public IActionResult GetCity(int id)
{
var cityToReturn = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == id);
//);
if (cityToReturn == null)
return NotFound();
else
return Ok(cityToReturn);
}
}
}
I was having the same problem. It is my first time using asp net core to build a web api and was struggling with this same issue.
use dotnet dev-certs https --trust
to build the certificate.
Then use dotnet run
To fix in postman go to the Settings -> General and turn off SSL certificate verification.
Hope it helps you.
Found out the answer in this video: ASP .NET Core - Fix Problem Postman cannot access due to SSL Certificate Error by CMVDev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With