简体   繁体   中英

How to fix CORS error when getting contents from a website?

There is a CORS error in my code that gets the contents from https://roblox.com/discover to clone the roblox discover page.

My code:

<?php
   echo file_get_contents("https://www.roblox.com/discover");
?>

If I go to console, it says

Access to XMLHttpRequest at 'robloxscript' from origin 'yoursite' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How can I go about fixing this?

You cannot do that. Because of security reasons. Different domain. For you to be able to consume that page you will have to fetch the data using a client request and manipulate the dom to get what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM