node.js - android 4.4 上的 Ionic 1 发行版存在 cors 错误
问题描述
在 android 4.4 上使用发布版本时,我目前遇到了 Ionic 1 的问题。我不断收到cors
错误消息。此外,我正在使用 node.js 后端cors
,其中已经指定了请求。这是到目前为止看到的错误:
SEC7121:[CORS]当凭证模式用于“ https://www.slywolf.co.za/api/auth/signin ”的跨源资源时,在响应标头中找到源“ http://localhost:8100 ” '。*
Access-Control-Allow-Origin
include
任何有关这方面的帮助将不胜感激。
解决方案
在你的 node.js 服务器中添加这个作为中间件。
这将允许使用凭据的跨源请求
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:8100");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST,PATCH, DELETE, PUT");
res.header("Access-Control-Allow-Credentials", true);
next();
});
推荐阅读
- swift - 使用 Swift @propertyWrapper 作为动态默认值?
- gaussian - GMM和HMM的区别
- sql - 如何在 Oracle 中获取 epoch 函数
- javascript - js中的流控会影响性能吗
- c# - 对等 C# 重置连接
- ruby-on-rails - 为什么下拉列表出现在框的后面?使用简单表单 + Select2
- python - Python cv2.imshow() 不工作:无法连接到 X 服务器
- rest - Postman:解析多部分 servlet 请求失败;嵌套异常是 java.lang.IllegalStateException, MultipartFile, REST
- rust - 为什么这个 HashMap 键必须被取消引用两次?
- java - LiveData 观察者的 onchanged() 方法执行多次