简体   繁体   English

角+ PHP登录API CORS问题

[英]angular + php login api cors issue

I am trying to do login in angular + php rest api, api is working in postman. 我正在尝试用angular + php rest api登录,该api在邮递员中工作。 I have added cors in php, same code is working with other site but now I am getting the below error. 我在php中添加了cors,相同的代码也可以在其他站点上使用,但是现在出现以下错误。

XMLHttpRequest cannot load http://www.yapp.tk/demo/kloxet/customers/login.json . XMLHttpRequest无法加载http://www.yapp.tk/demo/kloxet/customers/login.json Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response. 在飞行前响应中,Access-Control-Allow-Headers不允许请求标头字段Access-Control-Allow-Headers。

$http({
            url: 'http://www.yapp.tk/demo/kloxet/customers/login.json',
            method: "POST",
            data: { email: $scope.username, password: $scope.password },
            //withCredentials: true,
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            }
        })
        .then(function(response) {
                console.log(response);
        }, 
        function(response) { // optional
                // failed
        });

You need to set cros allow from php. 您需要从php设置cros allow。 It has nothing to do with angular. 它与角度无关。 Check for cros filter in php. 检查php中的cros过滤器。 And it's yelling on preflight when your application is doing an option request. 当您的应用程序正在执行选项请求时,它会对预检大吼大叫。 It can depend on if you are doing basic authentication from php and it's doing authentication even on the option request witch it should not do. 它可能取决于您是否正在从php进行基本身份验证,甚至是否应该执行不应该执行的选项请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM