【问题标题】:"Could not get any response" in Postman邮递员中的“无法得到任何回应”
【发布时间】:2019-03-20 01:30:29
【问题描述】:

我正在学习 ASP.NET Core。我为此目的使用的服务器是 Postman,我从光盘导入一个 JSON 文件。 API 的代码是在 Visual Studio 中编写的,并且编译时没有错误。 当我在 Postman 中发送 GET 请求时,我收到此错误:“无法获得任何响应”。 为了解决这个问题,我对设置进行了更改(参见附图),但这不是解决方案。你能用这个取悦我吗?

这是显示 GET 请求和我得到的错误的屏幕截图:

控制器的代码:

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);
        }
    }
}

【问题讨论】:

  • 你能告诉我们邮递员请求和API端点(包括路由)吗?
  • 如果有请求消息,请考虑查看服务器控制台(Visual Studio - 输出窗口)
  • 能否请您附上您尝试执行的 C# 操作的屏幕截图?
  • 您可以通过浏览器而不是 Postman 访问端点吗?
  • @MaYaNicolson 如果这就是你的全部,那么你的服务器没有开始监听任何地址:端口和/或邮递员无法到达它。在服务器初始化阶段之后应该有一个输出,如:“starting server on 0.0.0.0:5000”。 (好像不相等!)

标签: asp.net-core postman


【解决方案1】:

我遇到了同样的问题。这是我第一次使用 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

【讨论】:

    猜你喜欢
    • 2020-09-20
    • 2017-11-18
    • 2018-09-24
    • 2019-12-23
    • 2018-06-03
    • 2019-04-01
    • 2015-08-21
    • 2020-08-10
    • 1970-01-01
    相关资源
    最近更新 更多