Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS policy block RESTFUL API response #29

Open
Wave125S opened this issue Dec 8, 2024 · 0 comments
Open

CORS policy block RESTFUL API response #29

Wave125S opened this issue Dec 8, 2024 · 0 comments

Comments

@Wave125S
Copy link

Wave125S commented Dec 8, 2024

I use fetch in javascript to request data from https://ssl-checker.io/api/v1/check/. Code below. However the browsers CORS policy blocks it and says "No 'Access-Control-Allow-Origin' header is present on the requested resource."
The browser offers opaque response with the option {mode: 'no-cors'}. This lets throught the request, but the result is no data.

const option = {mode: 'no-cors'}; fetch (url, option).then(res => { if (!res) { console.log('Response not ok!'); return; } console.log(res); return res.text(); }).then(data => console.log('data:', data)).catch(error => console.log(error));

I have also tried return res.json(); instead of return res.text();, which results in SyntaxError: Unexpected end of input at 'json()'.

Does the API request require anything more than the url (g.e. 'cnn.com')?

/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant