I am trying to make in JS smth like:

curl -I -X GET https://www.youtube.com/oembed\?url\=http://www.youtube.com/watch\?v\=12345

this is returning status codes etc. In wordpress for example there is a method:

get_headers('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v='.$id)

which works fine.

But in JS I have a problem... I was trying fetch or axios:

return await axios({
              method: 'get',
              url: url,
              headers: {"Access-Control-Allow-Origin": "*"},
              maxRedirects: 5
            });

axios returns me:

Access to XMLHttpRequest at 'http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=12345' from origin 'http://localhost:8888' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

and all the time I am occuring some CORS errors or about redirects. I see those calls are being done ( in dev console ) but no response codes:

return await fetch('http://www.youtube.com/oembed\?url\=http://www.youtube.com/watch\?v\='+id, {
                 method: 'GET',
                 mode: 'no-cors',
                 headers: {
                    'Accept': 'text/plain',
                    'Content-Type': 'text/plain'
                }
             }).then(function(response) {
                 console.log('response: '+response.status);
                return 123;
             });

this fetch for example shows me 0 as a response.status.. VM4311:1 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=12345 with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details. Any one can help me ? thanks!

0 Answers