Answer the question
In order to leave comments, you need to log in
Local request to vk api via axios returns No 'Access-Control-Allow-Origin' header is present on the requested resource?
On React, I make a request to the VK API via axios. I'm making a request to localhost.
componentDidMount() {
axios.get('https://api.vk.com/method/groups.getById?gid=27541941&fields=members_count')
.then(res => {
const lol = res.data;
console.log(lol);
});
}
MLHttpRequest cannot load https://api.vk.com/method/groups.getById?gid=39094469&fields=members_count. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://smns.loc' is therefore not allowed access.
Answer the question
In order to leave comments, you need to log in
SOLVED part of the problem. The point is that axios only works with json. And cross-domain requests for vk api require type: jsonp. I tried to make a jQuery request with type: jsonp and everything works. The only question is what to use on React for JSONP....?
It has to do with https. The request must be either from a domain with https. Try to remove https: from url'a.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question