1

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',
    }
})

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.