Reputation: 119
I am using ajax to post to an endpoint within a javascript function. Before I post, I set a header with the name 'Cookie' on the request. I have tried setting the header both using beforeSend and using 'headers' (see code below), but the header is only sometimes set. Much of the time the 'Cookie' header is not set. I can tell this by looking at the header in firebug for a Post request. I only have this problem with the header named 'Cookie'. All other headers are consistently set. I can't change the name of the 'Cookie' header to a different value as it is required for the service that I am calling.
$.ajax({
url:url,
type:'POST',
contentType: "application/xml",
beforeSend: function (request)
{
request.setRequestHeader("Cookie", authCookie);
request.setRequestHeader("Authorization", "Authentication id=company.platform.services.org.test,app_secret=aEWEvsddsdddddds0");
},
headers: {"Cookie": "abc.etc.authid=" + companyID + ",abc.etc.ticket=" + ticket, "Authorization": "Authentication id=company.platform.services.org.test,app_secret=aEWEvsddsdddddds0"},
data: order,
success: createOrderCallback,
error: createOrderError
});
Is there a better way to set this header to ensure that it will always be set for each request?
Upvotes: 0
Views: 342
Reputation: 140230
It is impossible to set the cookie header with XHR http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method
The only reason it appeared to work is probably because you had actual cookies the browser sent.
Upvotes: 1