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

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

问题描述

我试图访​​问数据的后期方法中,它的名字是登录(),但是当URL是产生转移到它的位置在当时的错误。


  

错误:-Refused连接到
  <一个href=\"http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp?Email=abc@gmail.com&Password=12345&crossDomain=true\" rel=\"nofollow\">http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp?Email=abc@gmail.com&Password=12345&crossDomain=true'
  因为它违反了以下内容安全策略指令:
  默认-SRC自我的数据:差距: https://ssl.gstatic.com 不安全-EVAL 。
  需要注意的是连接-src'中没有明确设置,因此'默认的src'是
  作为后备。


我收拾了允许控制允许原产地:*。扩展并安装它到Chrome,但它不能正常工作

code

  $ scope.Login =函数(回调){
    $ HTTP({
        方法:邮报,
        网址:http://smartlearner.com/SmartLearner/UserAccount/LearnerLoginByMobileApp
        params:一个{
            密码:$('#密码)VAL()。
            电子邮件:$('#电子邮件)VAL()。
            跨域:真
        }
    })。成功(功能(数据){        //这里做一些事情    }, 回电话)
    .error(功能(数据,errorThrown){       //这里做一些事情    }, 回电话);
};


解决方案

您需要安装白名单插件,让您在科尔多瓦的应用程序XHR支持。你不能让外部请求离不开它了。

运行:科尔多瓦插件添加https://github.com/apache/cordova-plugin-whitelist.git

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.

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.

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

Code

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

解决方案

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

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

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

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