$http doesn't send cookies

5,779 views
Skip to first unread message

levyuk

unread,
Aug 24, 2012, 1:16:54 PM8/24/12
to ang...@googlegroups.com
HI all,

I might be being thick here but whenever I use $http to request something from a server the cookies are not sent with the request and so the request isn't authorised. What am I doing wrong? Do I have to tell angular to send the cookies? If so how? I've looked for information on http withCredentials but it's impossible to find.

Thanks
Jon

esca...@gmail.com

unread,
Aug 25, 2012, 11:00:19 AM8/25/12
to ang...@googlegroups.com
Hi Jon,

I am just an user but the cookies should be automatically sent with $http. I am inspecting the xhr request of my app and the cookies are there. I don't have any special configuration.

Are you sure you are not having cookie path/domain problems?

sbil...@heilmannsoftware.de

unread,
Sep 27, 2012, 7:59:39 AM9/27/12
to ang...@googlegroups.com
I'm pretty sure it's a cross domain issue. XHR cross domain requests don't include cookies by default. The XHR.withCredentials attribute has to be set to true. I'm currently looking for an opportunity to configure this in angular. If you are able to reach the jQuery instance it uses, you can do it by $.ajaxSetup({xhrFields: {withCredentials: true}, crossDomain: true});

Stefan

gdan...@gmail.com

unread,
Sep 30, 2012, 4:25:14 PM9/30/12
to ang...@googlegroups.com
The $http service has config option called withCredentials. Set it to true. Do the same on the server side. Return header Access-Control-Allow-Credentials: true. There is good tutorial at http://www.html5rocks.com/en/tutorials/cors/
Greg

Andrey Stegno

unread,
Apr 24, 2014, 12:58:01 PM4/24/14
to ang...@googlegroups.com
I have same issue. It isn't cross domain. withCredentials doesn't help. I can see console.log($cookies.sessionID). Right after $http.post doesn't send sessionID. It means I have wrong request. 
Reply all
Reply to author
Forward
0 new messages