Access-Control-Allow-Origin workaround
See original GitHub issueI an trying to to a simple get request, and I get an Access-Control-Allow-Origin
error
Vue.http.get('https://some_url').then(response => {
console.log(response);
}, response => {
console.log(response);
});
If I do a regular xhr
request, I don’t get the error and all is good
let createCORSRequest = function (method, url) {
let xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest !== "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
};
let xhr = createCORSRequest('GET', 'https://some_url');
xhr.onload = function () {
console.log(JSON.parse(this.responseText));
};
xhr.onerror = function () {};
If I try to do a jsonp
request instead, I get Uncaught SyntaxError: Unexpected token :
, basically failing to parse the json response.
Vue.http.get('https://some_url').then(response => {
console.log(response);
}, response => {
console.log(response);
});
Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
how to bypass Access-Control-Allow-Origin? - Stack Overflow
there is no way to baypass it. but you can put a file on your backend that performs the request. So you call...
Read more >3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >CORS - Misconfigurations & Bypass - HackTricks
You can ask a web-application to make a request for you and send back the response. This will bypass the Access-Control-Allow-Origin but notice...
Read more >Access-Control-Allow-Origin - HTTP - MDN Web Docs - Mozilla
The Access-Control-Allow-Origin response header indicates whether the response can be shared with requesting code from the given origin.
Read more >How to bypass 'Access-Control-Allow-Origin' error with ...
If you're a curious developer in some point of your life you may already faced (or you will face) the cross-domain/same-origin policy.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Enables cross-origin requests to anywhere via proxy.
I cant change
'Access-Control-Allow-Origin': '*'
as you suggested because I am using apis like github oauth. I am not building an API I am using it