拒绝连接到 [Any Url],因为它违反了以下内容安全策略指令 [英] Refused to connect to [Any Url] because it violates the following Content Security Policy directive

查看:73
本文介绍了拒绝连接到 [Any Url],因为它违反了以下内容安全策略指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问 post 方法中的数据,它的名称是 Login() 但是当 URL 传输到它的位置时会产生错误.

I am trying to access data within post method and its name is Login() but when URL is transfer to its location at that time Error is generated.

错误:-拒绝连接'http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp?Email=abc@gmail.com&Password=12345&crossDomain=true'因为它违反了以下内容安全策略指令:"default-src 'self' 数据:gap: https://ssl.gstatic.com 'unsafe-eval'".请注意,'connect-src' 没有明确设置,所以 'default-src' 是用作后备.

Error:-Refused to connect to 'http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp?Email=abc@gmail.com&Password=12345&crossDomain=true' because it violates the following Content Security Policy directive: "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.

我打包了 "Allow-Control-Allow-Origin: *" 扩展并将其安装到 chrome 中,但它不起作用.

I packed the "Allow-Control-Allow-Origin: *" extension and installed it into chrome but it does not work.

代码

 $scope.Login = function (callback) {
    $http({
        method: "Post",
        url: "http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp",
        params: {
            Password: $('#Password').val(),
            Email: $('#Email').val(),
            crossDomain: true
        }
    }).success(function (data) {

        //Do Something here

    }, callback)
    .error(function (data, errorThrown) {

       //Do Something here

    }, callback);
};

推荐答案

您需要安装白名单插件 允许在您的 Cordova 应用程序中支持 XHR.没有它,您就无法发出外部请求.

You need to install the whitelist plugin to allow XHR support in your Cordova app. You can't make external requests without it.

运行:cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git

这篇关于拒绝连接到 [Any Url],因为它违反了以下内容安全策略指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆