【问题标题】:Refused to connect to [Any Url] because it violates the following Content Security Policy directive拒绝连接到 [Any Url],因为它违反了以下内容安全策略指令
【发布时间】:2015-08-14 14:07:04
【问题描述】:

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

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

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

代码

 $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);
};

【问题讨论】:

    标签: angularjs cordova angularjs-http


    【解决方案1】:

    您需要安装 whitelist plugin 以允许在您的 Cordova 应用程序中支持 XHR。没有它你就不能发出外部请求。

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

    【讨论】:

    • 当然! cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git
    猜你喜欢
    • 2012-11-27
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 2020-06-23
    • 2015-09-21
    • 1970-01-01
    • 2013-07-19
    相关资源
    最近更新 更多