[英]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.