.NET5 Web API 返回 404 Not Found

问题描述

我正在本地计算机 (Win10) 上设置我的第一个 .NET5 Web API。为了测试,我制作了这个简单的控制器:

namespace API.Controllers
{
    public class TestController : Controller
    {
        [HttpGet]
        [Route("/test/hallo")]
        public string TestMethod()
        {
            return "Hallo";
        }
    }
}

当运行/调试来自 VS2019 的代码时,这个 url 打开: https://localhost:5001/swagger/index.html

当我在 Swagger 页面中执行“test/hallo”时,它按预期返回“Hallo”。

请求网址是: https://localhost:5001/test/hallo

到目前为止,一切都很好!

当我尝试从 Google Advanced REST Client 运行 API 时出现问题。我在请求 URL 中选择 Method = "Get" 和 "https://api.mydomain/test/hallo"。它返回 404 Not Found。

本地域“api.mydomain”在我的计算机上使用自签名证书。它似乎工作正常,我已经通过在项目根目录中添加“test.html”来测试它。在 Google Chrome 中打开 https://api.mydomain/test.html 时,页面显示正确。

最大的问题是:当我尝试使用 Google Advanced REST Client 使用本地域 (api.mydomain) 访问 API 时,为什么会出现“404 Not Found”?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)