无法读取Set-Cookie响应标头 [英] Not able to read Set-Cookie response header

查看:349
本文介绍了无法读取Set-Cookie响应标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的api调用,我正在尝试从响应标头中读取Set-Cookie

Here is my api call, I am trying to read Set-Cookie from response header

 return $http(config).then(function (response) {
      console.log(response.headers('Set-Cookie')); // undefined
      console.log($cookies.ovrcMfa); // undefined
    return response.data;
  });

,响应标​​头为:

Access-Control-Allow-Credentials: true 

Access-Control-Allow-Headers: Content-Type, Authorization, Set-Cookie, X-Requested-With, X-Session-Id, X-App-version, X-Target-Client, X-Origin-Domain, X-Dev-Mode

Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS

Access-Control-Allow-Origin: *

Access-Control-Expose-Headers: Set-Cookie

Set-Cookie : ovrc-mfa=IHfpt06ogxzLQFpwySE7vaJYg7whQ0sF; Max-Age=31536000; Path=/; Expires=Thu, 16 Jan 2020 09:30:47 GMT

在这里,我想读取Set-Cookie值,即ovrc-mfa

Here I want to read Set-Cookie value ie ovrc-mfa

推荐答案

Set-Cookie

Set-Cookie is a forbidden response header name. You cannot read it using browser-side JavaScript.

如果您需要将该信息传递给JavaScript,则需要让服务器使用其他某种机制(例如,不同的标头或响应主体的一部分).

If you need to pass that information to your JavaScript, then you need to have the server use some other mechanism (such as a different header or part of the response body).

这篇关于无法读取Set-Cookie响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆