I'm currently writing an angularjs frontend to my backend, and I'm running into a somewhat common issue:
Server sends a cookie back in a response, but is completely ignored by angular.js (can't even print out the 'Set-Cookie' value).
I've tried reading
Set-Cookie in HTTP header is ignored with AngularJS
Angularjs $http does not seem to understand "Set-Cookie" in the response
but unfortunately I've tried all the solutions there and just doesn't seem to work.
Request sent
Response received
I'm using angular.js (v1.2.10), and this is what I used to make the request
$http.post('/services/api/emailLogin',
sanitizeCredentials(credentials),
{
withCredentials: true
}).success(function(data, status, header) {
console.log(header('Server'));
console.log(header('Set-Cookie'));
console.log(header('Access-Control-Allow-Headers'));
console.log(header('Access-Control-Allow-Methods'));
console.log(header);
}).then(
function(response) {
console.log(response);
return response.data;
});
withCredentials=true
is set on the client side before making the request.
Access-Control-Allow-Credentials=true
is set on the server side before returning the response.
You can clearly see Set-Cookie
is in the response headers from Chrome Developer Tools, but printout is just
Only Set-Cookie
in the response header is not being printed out. I'm wondering why does this occur? Is there a way for me to make sure withCredentials=true
is indeed set (I didn't see it in the request header)?
Any help is appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…