Question: Create an axios post request to access a given API. I have the following code so far but I get the following error. Access to
Create an axios post request to access a given API. I have the following code so far but I get the following error.
Access to XMLHttpRequest' from origin has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Here is my code so far:
axios.defaults.headers.common['Authorization'] = token;
axios.defaults.headers.common['Context-Type'] = 'application/json';
axios.defaults.headers.common['Accept'] = 'application/json';
axios.defaults.headers.common['Client_ID'] = '**************************************';
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
axios.defaults.headers.common['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
axios.post(url,{
data: "fields akas,checksum,country_name,created_at,description,games,gender,mug_shot,name,slug,species,updated_at,url;"
})
.then(response => {
console.log(response.data);
this.setState({ games: response.data })
})
.catch(err => {
console.error(err);
});
}
render() {
return (
)
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
