[英]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.我的代码中有一个 CORS 错误,它从https://roblox.com/discover获取内容以克隆 roblox 发现页面。
My code:我的代码:
<?php
echo file_get_contents("https://www.roblox.com/discover");
?>
If I go to console, it says如果我 go 控制台,它说
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.
CORS 策略已阻止从来源“yoursite”访问“robloxscript”处的 XMLHttpRequest:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”header。
How can I go about fixing this?我怎样才能 go 解决这个问题?
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.
为了能够使用该页面,您必须使用客户端请求获取数据并操作 dom 以获得您想要的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.