0

我正在从本地主机向远程服务器发送一个 post auth 请求,以获取服务器返回的响应 cookie(使用离子代理解决 CORS)。从 chrome 网络检查器,我可以看到响应 cookie 已从服务器返回。但是,我无法从 $http 发布响应中访问它。我几乎尝试了其他帖子中的所有内容,但我仍然无法获得 cookie。我试过的

  • 我使用 ngCookie 和 $timeout 组合。基本上,当我使用 $cookie.getAll() 时我得到一个空对象,我假设 cookie 不存在
  • 我还将 withCredentials 设置为 true
  • 我也试过 headers.get('set-cookie')

我的角度版本是 1.5.3。请帮忙

下面是我的代码

angular.module('starter.controllers', ['ngCookies'])

.controller('DashCtrl', function($scope, $http, $cookies, $timeout) {
$http({
    method: 'POST',
    url: '/api/User/Authenticate',
    data: {
      Username: 'xxx',
      Password: 'xxx'
    },
    withCredentials: true
  }).then(function(response) {
    $timeout(function() {
      console.log($cookies); // return {}
      console.log($cookies.getAll()); // return {}
    });
  }, function(response) {

  });
})

这是服务器响应 在此处输入图像描述

4

0 回答 0