【发布时间】:2023-03-14 15:04:01
【问题描述】:
我正在尝试向特定网站发送 HTTP 请求,但遇到错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.google.com/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
例如,我想向 Google.com 发送请求并接收 HTML 响应。 我的代码是使用 JQUERY AJAX 编写的:
function sendRequest(URL) {
$.ajax({
type:'GET',
url:URL,
success:function(result){console.log(result);}
});
}
【问题讨论】:
-
简短的回答是你不能,除非目标站点通过 CORS 或其他一些明确的方法明确允许它。这是一项基本的安全措施,无法绕过。
-
认为消息说的都是“不允许读取google.com 的远程资源。(原因:缺少CORS 标头'Access-Control-Allow-Origin')。”
-
您需要回复吗?如果没有,请使用表单、img 或信标。
标签: javascript jquery ajax http