简体   繁体   中英

AngularJS: request fails when withCredentials : true (request canceled)

I have this problem with AngularJS $http request:

This works:

$http({url : endpoint, withCredentials: false}); // success

This doesn't:

$http({url : endpoint, withCredentials: true}); // error

Server configuration:

header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");

When I look into the Google Chrome console I see Status: (canceled) and warning: "provisional headers are shown". What's interesting, in Opera request status is OK and I can see the response.

I've been looking for an answer and found nothing. Any ideas?

Ok, it seems that it was about Access-Control-Allow-Origin wildcard. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Setting it to:

header("Access-Control-Allow-Origin: http://the.domain.it.was.called.from");

solved the problem.

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