javascript - 欺骗站点认为请求来自它的域
问题描述
我尝试发出跨域ajax请求,总是得到0状态响应,现在,似乎明白了问题所在。在站点方面,可以有一个可以向其发送请求的域列表。据我了解,它是通过下一种方式设置的:
Access-Control-Allow-Origin: http://example.com
据我了解,当我向另一个域发出请求时,浏览器会自动添加到请求的标头值Origin
中,其中包含请求来自的域。
那么,如果更改该标头值,服务器会被欺骗吗?怎么办?
<?php
$url = $_POST['url'];
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $_POST['data']
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE)
echo('error');
else
echo($result);
?>
解决方案
推荐阅读
- magento2 - 从 CMS 块调用 .phtml 文件 - Magento 2
- javascript - 查找数组和对象数组之间的匹配项
- mysql - mySQL-在单列下添加数据
- apache-kafka - Flink `/bin/sql-client.sh` 从 Kafka 读取时抛出 NoSuchMethodError
- django - 如何使用 Google App Engine + Django 和 JQuery File Upload 将大文件上传到 Google Storage
- text - SwiftUI 位置文本右下角?
- elasticsearch - Elasticsearch 自动完成建议器
- android - 如何在 RecycleViwer 中用 Kotlin 编写 PopupMenu?
- java - 如何在 Google Cloud Platform 上的 Shell 中运行 Headless Chrome
- python - 将值重采样为更小的值