Skip to content

CORS policy block RESTFUL API response #29

@Wave125S

Description

@Wave125S

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions