I've built an API with C# that works fine when I do a "Get" from Postman.
Now, I'm trying to perform the same "Get" using an HTML web page that I'm building.
Here's my HTML so far:
<!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>
And here is the method in my API that I'm trying to perform the "Get" on:
//https://localhost:44369/api/Request
[EnableCors("AllowLocalhostOrigins")]
[HttpGet]
public ActionResult GetText()
{
string a = "b";
return Ok(a);
}
Here's the Error:
I've read about the CORS, but I'm not clear on what I need to do in the HTML to make it work. The API returns the "Get" request just fine in Postman so I know that the API at least functions properly.