I'm developing a phonegap application that needs to connect to a staless remote server. Some of the remote requests are authenticated and I was planning to use a remember-me service. So from the application there is a login option that is translated into the following request executed with jQuery $.ajax. Notice that all the requests are application/json
POST remoteserver/api/users/login
and the server responds setting a cookie
Set-Cookie REMEMBER_ME_COOKIE=amVzdS5hbG9uc29AZ21haWwuY29tOjEzNTEwMDg1NTg1NDY6ODdkOGFhNzEzY2NiZTRhZTIwZjZlNzgyY2E1ZmQyODY; Expires=Tue, 23-Oct-2012 16:09:18 GMT; Path=/; HttpOnly
In order to make cross domain requests work, the server responds as this for OPTIONS requests:
Access-Control-Allow-Headers : Content-Type, *
Access-Control-Allow-Origin : *
Access-Control-Max-Age : 1000
However the next request to the server is not setting the Cookie header.
1) Is it possible to make cookies work?
2) I have also tried to add the cookies manually in the $.ajax request, but it does not work either. Is it something wrong?
$.ajax({
type : type,
url : url,
data : data,
success : callback,
dataType : dataType,
contentType : contentType,
beforeSend: function(xhr) {
xhr.setRequestHeader("Cookie", "REMEMBER_ME_COOKIE=amVzdS5hbG9uc29AZ21ha");
},
error : function(jqXHR, textStatus, errorThrown) {
handleError(jqXHR, textStatus, errorThrown);
}
});