Post api request to create a new post

[ad_1]

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]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer