相关疑难解决方法(0)

$ http请求不会在角度CORS中发送cookie跨域

首先,我想告诉我,我已经阅读了Stack中的所有问题以及与CORS相关的所有问题,但实现仍然无效.我的APP建立在角度crud演示之上:

所以我在app配置中:

$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
Run Code Online (Sandbox Code Playgroud)

我知道它们设置正确(通过调试).在我的"安全"应用程序中,我正在请求当前用户,跨域:

return $http.get(LAYOUT_CONFIG.baseURL + '/current-user').then(function(response) {
      //service.currentUser = response.data.user;
      service.currentUser = response.data;
      return service.currentUser;
    });
Run Code Online (Sandbox Code Playgroud)

我在第一次请求时得到这些标题:

    Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:accept, origin, content-type, cookie
Access-Control-Allow-Methods:GET,POST
Access-Control-Allow-Origin:http://admin.vibetrace.com
Access-Control-Max-Age:1728000
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Sun, 02 Jun 2013 11:07:49 GMT
P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server:nginx/1.1.19
Set-Cookie:vibetrace.ssid=s%3A2lT2_N0-EevCJt7LbRlJ6Az1.d8xp99st%2F0RNV0VN2D4o4AJXNRT%2F%2F46v8PDVWSAbx%2Fw; Path=/; Expires=Mon, 30 Sep 2013 11:07:49 GMT
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Cache:MISS
X-Powered-By:Express
Run Code Online (Sandbox Code Playgroud)

所以Set-Cookie就在那里.但是,后续的$ http.get请求(来自angular)不会发送应该先前已设置的cookie.

Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch …
Run Code Online (Sandbox Code Playgroud)

jquery cors angularjs

35
推荐指数
1
解决办法
4万
查看次数

标签 统计

angularjs ×1

cors ×1

jquery ×1