I am confused why my c# WebAPI call is failing to fetch from JavaScript and is always just returning an empty string.
Here is my method in my C# API controller
[AllowAnonymous]
[Route("GetApiExample")]
[HttpPost]
public IHttpActionResult GetApiExample()
{
return Ok(new { success = true });
}
Here is my javascript
fetch('https://localhost:44363/api/Example/GetApiExample', {
method: 'POST',
mode: 'no-cors',
})
.then((response) => response.text())
.then((json) => console.log(json));
I'm assuming it must be something on the c# side or the fact is needs no-cors on it.
Anyone have any ideas?
** UPDATE **
I have updated to the answer as below but this still brings back an empty string