简体   繁体   中英

angular + php login api cors issue

I am trying to do login in angular + php rest api, api is working in postman. I have added cors in php, same code is working with other site but now I am getting the below error.

XMLHttpRequest cannot load 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.

$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. It has nothing to do with angular. Check for cros filter in php. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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