Set-Cookie in HTTP header is ignored with AngularJS

后端 未结 6 1510
旧时难觅i
旧时难觅i 2020-12-02 11:50

I\'m working on an application based on AngularJS on client side and Java for my API (Tomcat + Jersey for WS) on server side.

Some path of my API are restricted, if

6条回答
  •  無奈伤痛
    2020-12-02 12:30

    You need work on both the server and client side.

    Client

    Set $http config withCredentials to true in one of the following ways:

    1. Per request

      var config = {withCredentials: true};
      $http.post(url, config);
      
    2. For all requests

      angular.module("your_module_name").config(['$httpProvider',
        function($httpProvider) {
          $httpProvider.interceptors.push(['$q',
            function($q) {
              return {
                request: function(config) {
                  config.withCredentials = true;
                  return config;
                }
              };
            }
          ]);
        }
      ]);
      

    Server

    Set the response header Access-Control-Allow-Credentials to true.

提交回复
热议问题