Reputation: 854
I'm using AngularJS 1.4.7. What I want to do is to make a cross origin request with JSON payload (application/json) with Cookie header, too.
I read different options and suggestions and still my cookie and the content type are not set.
And I'm getting Refused to set unsafe header "Cookie" error message.
I try to add the "withCredentials:true" to the config but without success.
mod.config(function($httpProvider) {
$httpProvider.defaults.withCredentials = true;
});
$http({
withCredentials: true,
method: POST,
url: url,
data: jsondata,
timeout: deferred.promise,
headers: {
'Content-Type': 'application/json',
'Cookie': 'PHPSESSID=am1miv3koldaqh0ppf9r75hdg1',
}
})
Upvotes: 1
Views: 529
Reputation: 943625
You can't set the cookie header manually for an XHR object. That is a firm rule (see Step 5 of the addRequestHeader process) and you can't change it with CORS.
If you want to set a cookie on a different origin, then you need to have that origin set it using an HTTP response.
Upvotes: 1