我正在学习 ASP.NET Core。我用于此目的的服务器是 Postman,我从光盘导入 JSON 文件。 API 的代码是在 Visual Studio 中编写的,并且编译无错误。
当我在 Postman 中发送 GET 请求时,收到此错误:“无法获得任何响应”。
为了解决这个问题,我对设置进行了更改(请参阅附图),但这不是解决方案。你能用这个让我高兴吗?
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);
}
}
}
最佳答案
我也遇到了同样的问题。这是我第一次使用 ASP Net Core 构建 Web api,并且正在努力解决同样的问题。
我是这样解决的:
使用dotnet dev-certs https --trust
构建证书。
然后使用dotnet run
要在 postman 中修复,请转到“设置”->“常规”并关闭 SSL 证书验证。
希望对您有帮助。
在这个视频中找到答案:ASP .NET Core - Fix Problem Postman cannot access due to SSL Certificate Error by CMVDev
关于asp.net-core - postman 中的"Could not get any response",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52819808/