[英]Angular 5 unable to read Set-Cookie from http response
我正在尝试从我从服务器获得的 HTTP 响应中读取 JSESSIONID cookie (Set-Cookie)。
当我试图得到回应时,我没有看到。
return this.http
.get(environment.domain + '/rest/getSessionConfirmationNumber',
{observe: 'response'})
.retryWhen(this.config.handleRetry)
.catch(this.config.handleError)
.map(response => {
console.log('getSession success')
console.log('The cookie jSession ',
this.cookieService.get('JSESSIONID'))
}
还使用了ngx-cookie-service包(这只给了我浏览器应用程序选项卡中存在的 cookie)
在 get 请求中也尝试过withCredential=true 。 引发某种 CORS 错误(插件已打开)。
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
EDIT1:尝试根据CORS更新 xml :当凭据标志为 true 时,无法在 Access-Control-Allow-Origin 中使用通配符
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>http://localhost:4200</param-value>
</init-param>
仍然不起作用。
你的代码有this.cookieService.get('JSESSOINID'))
,你有this.cookieService.get('JSESSOINID'))
应该是this.cookieService.get('JSESSIONID'))
我遇到了同样的问题,我在 get 请求中的 url 部分之后使用withCredential=true修复了它。 并处理Cors错误在服务器端(.net core)的启动文件中的ConfigureServices函数中添加这段代码
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder =>
{
builder.WithOrigins(Configuration.GetSection("AllowedOrigins").Get<string[]>())
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.