简体   繁体   English

从网站获取内容时如何修复 CORS 错误?

[英]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.

相关问题 如何修复尝试制作多人蛇游戏时遇到的 CORS 错误 - How do I fix a CORS error that I'm getting when trying to make a multiplayer snake game 如何从具有 AJAX 请求的网站获取 HTML 页面而不出现 CORS 错误? - How do I get HTML page from a website with AJAX request without getting CORS error? 从反应应用程序向快递服务器发送请求时如何修复CORS错误 - How to fix CORS error when sending a request to express server from react app 上传到 Cloudinary 时如何修复 CORS 阻止错误 - How do I fix CORS blocked error when uploading to Cloudinary 如何在不看到 CORS 错误的情况下从网站 URL 获取图标? - How to get a favicon from a website URL without seeing a CORS error? 从本地服务器请求JavaScript时,Rails收到CORS错误 - Rails getting CORS error when requesting javascript from the local server 即使在后端设置了 cors,如何修复 cors 错误 - How to fix cors error faced even with cors setup on the backend 如何修复 localhost 中的反应 cors 错误? - How to Fix react cors error in localhost? 如何仅在Safari中修复XMLHttpRequest cors错误? - How to fix XMLHttpRequest cors error in Safari only? 如何使用凭证修复CORS错误:包含? - How to fix CORS error with credentials: include?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM