简体   繁体   English

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

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

Trying to perform a "get" request to API. I know the API will return the data when I do the "get" from Postman. So I believe the problem is with my HTML.尝试对 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>

Here's the API method I'm trying to "get" from:这是我试图从中“获取”的 API 方法:

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

        return Ok(a);
    }

Here's the error I'm getting: 404 Not Found这是我收到的错误: 404 Not Found

After doing some more reading, I see that it's a problem with the API and not the html code I posted this question about.在做了更多阅读之后,我发现这是 API 的问题,而不是我发布此问题的 html 代码。 The html code I posted works fine.我发布的 html 代码工作正常。

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

相关问题 使用 axios 执行 GET 请求时出现 401 错误 - 401 error when performing GET request w/ axios 404错误获取错误请求快速API React.js,从api url获取sneakerId - 404 error GET bad request Rapid API React.js, get sneakerId from the api url 尝试从Google Map API获取照片时出现404错误 - 404 Error when trying to get the photos from Google Map API 从Node.js中的AWS S3 getSignedUrl对URL执行获取请求时出现SignatureDoesNotMatch错误 - SignatureDoesNotMatch error when performing get request on URL from AWS S3 getSignedUrl in Node.js 删除api请求以404错误响应 - DELETE api request responds with 404 error GET请求错误404(未找到)使用axios - GET request error 404 (not found) using axios 获取请求在 Angular 5 应用程序中抛出 404 错误 - get request throwing 404 error in Angular 5 app Corda Settler UI-尝试通过API发送问题请求时出现错误404 - Corda Settler UI - Error 404 when trying to send an issue-obligation request via API 从 chrome 扩展向 google execution api 发布请求时出现 404 错误 - 404 error when posting request to google execution api from chrome extension 尝试对 Hubspot 表单 next.js 应用程序发出 api POST 请求时出现 404 错误 - Getting a 404 ERROR when trying to make api POST request for a Hubspot form next.js app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM