javascript - 由于访问控制检查,无法加载带有数据的 JS 客户端/Python 服务器 XMLHttpRequest 帖子
问题描述
我正在编写一个 Python 服务器和一个 JavaScript 客户端。
服务器必须在某个发布请求中获取一些数据。测试它:
curl --header "Content-Type: application/json" --request POST --data '{"name":"test"}' "https://server_url/op?param=p"
完美运行。
如果我从客户端调用服务器:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = () => {
if (xhttp.readyState == 4) {
// Do some stuff
}
};
xhttp.open('POST', 'server_url/op?param=p', true);
xhttp.send();
它也可以完美运行,但当然会响应它缺少数据。但是,如果我用这个调用服务器:
xhttp.setRequestHeader('Content-Type', 'application/json');
xhttp.send(JSON.stringify({'name': 'test'}));
我不断收到“由于访问控制检查而无法加载”错误,服务器没有响应......我做错了什么?
解决方案
推荐阅读
- symfony - Symfony 4.1 的 SQLite 环境
- amazon-web-services - 如何处理具有各种“自定义”字段的数据的 ETL / ELT?
- java - JavaFX ObjectOutputStream 只返回 null
- python - OpenPyXL - 如何查询单元格边界?
- swift - swift uipickerview 高度更改不起作用
- swift - 检索最佳分数 Game Center Swift
- typescript - Cocos Creator 和 TypeScript 使用枚举作为属性
- php - 在蓝图中使用页面内容
- google-chrome - 创建 ChromeApps 仍然有意义吗?
- kivy - 无法使用 buildozer 从 kivy 创建 APK 文件