繁体   English   中英

向 API 执行“获取”请求时出现 404 错误

[英]404 error when performing "Get" request to API

尝试对 API 执行“获取”请求。我知道当我从 Postman 执行“获取”时,API 将返回数据。所以我相信问题出在我的 HTML 上。

<!DOCTYPE html>
<html>
<body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>

        <script>
            const Http = new XMLHttpRequest();
            const url='https://localhost:44369';
            Http.open("GET", url);
            Http.send();

            Http.onreadystatechange = (e) => {
            console.log(Http.responseText)
            }

        </script>
</body>
</html>

这是我试图从中“获取”的 API 方法:

    //https://localhost:44369/api/Request
    [EnableCors("AllowLocalhostOrigins")]
    [HttpGet]
    public ActionResult GetText()
    {
       string a = "b";

        return Ok(a);
    }

这是我收到的错误: 404 Not Found

在做了更多阅读之后,我发现这是 API 的问题,而不是我发布此问题的 html 代码。 我发布的 html 代码工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM