[英]Making CORS with AngularJS with Cookie
I'm using AngularJS 1.4.7. 我正在使用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.
我想做的是也使用带有Cookie标头的JSON有效负载(application / json)进行跨源请求。
I read different options and suggestions and still my cookie and the content type are not set. 我阅读了不同的选项和建议,但仍然没有设置我的cookie和内容类型。
And I'm getting Refused to set unsafe header "Cookie" error message. 而且我越来越拒绝设置不安全的标题“ Cookie”错误消息。
I try to add the "withCredentials:true" to the config but without success. 我尝试将“ withCredentials:true”添加到配置中,但是没有成功。
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',
}
})
You can't set the cookie header manually for an XHR object. 您不能为XHR对象手动设置cookie标头。 That is a firm rule (see Step 5 of the addRequestHeader process) and you can't change it with CORS.
这是一个严格的规则(请参见addRequestHeader流程的第5步),您无法使用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. 如果要在其他来源上设置Cookie,则需要使用HTTP响应将该来源设置为Cookie。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.