Hello! I’m using axios to make API requests, using WordPress as backend for API and VueJS as frontend (don’t ask me why, it’s a programming school project).
First, I got a 401 error about authorization, which I solved. Now that it’s solved, I get an error about CORS policy. Do you guys know what’s the problem?
the function:
deletepost(id) {
axios.delete(‘http://localhost:8080/wp-json/wp/v2/posts/’ + id, {
headers: {
‘Content-Type’: ‘application/json’,
‘username’: ‘username’,
‘password’: ‘pwd’
}
});
},
the error:
Access to XMLHttpRequest at ‘http://localhost:8080/wp-json/wp/v2/posts/1’
from origin ‘http://XX.XX.XXX.XX:8081’ has been blocked by CORS policy: Request
header field username is not allowed by Access-Control-Allow-Headers in
preflight response.
(note that the port 8081 is the port used by VueJS and 8080 is the port used by WordPress), both hosted locally on the same machine, my laptop.
Thanks for reading! Have a great day 🙂
[ad_2]