Тема: blocked by CORS policy
Hi guys,
I am a junior developer and I am trying to make a request to the wialon remote api, I run the tests from postman to validate that the url is correct, but when passing it to a Fetch request from the browser it gives me the following error.
Access to fetch at 'https://hst-api.wialon.com/wialon/ajax. … %TOKEN%22}' from origin 'http://localhost:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
The request I am making is very simple.
I would like to know what I am doing wrong so I can fix it.
Request with Fetch
const btn = document.getElementById('btn');
const token =''
const url = `https://hst-api.wialon.com/wialon/ajax.html?svc=token/login¶ms={"token":"${token}"}`;
btn.addEventListener('click', ()=>{
const requestOptions = {
method: 'POST',
Headers:{
'Access-Control-Allow-Origin': '*',
'body-type:': 'x-www-form-urlencoded'
}
};
fetch(url, requestOptions)
.then(response => response.Json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
})
I appreciate any help