如何在angularjs中将cookie作为header传递给使用drupal的远程应用程序[403禁止]

How to pass cookie as header in angularjs to a remote application that uses drupal [403 Forbidden]

本文关键字:drupal 应用程序 禁止 中将 angularjs cookie 作为 header      更新时间:2023-09-26

你好,我试图使一个$http get请求到一个远程应用程序,使用drupal在agular.js。每次我发出get请求,都会得到一个403响应,上面写着[匿名用户]。我能够发出put请求并获得带有令牌、session_name和session_id的响应。我的问题是我不确定如何传递cookie作为请求头的一部分。** **我尝试传递cookie作为标头,但仍然得到403响应。任何建议都会有所帮助。我甚至尝试使用$cookie.put('KEY,cookie)来保存cookie,但我仍然得到相同的响应。

var headers = {'Content-Type':'application/json','Cookie':xxxxxx=tokexxxx};
$http.get(url,headers).success(function(data){
        // response of the results 
        console.log('this is the repsonse that come from the get request', response);
}).error(function(err){// 403 error});

我的登录服务是这样的

angular.module('app.services', []).service('LoginService', function($rootScope,$q,$http,$cookies) {
    // this is the function that is called when ther user logins 
       var service = {};
       // get cridentials of the user 
       service.LogIn = function(username,password,callback){
            var loginStatus = [];
            var BASEURL=  http://xxxxxx.com';
            var parameters ={username: username,password: password};
            var headers = {'Content-Type':'application/json'}
            $http.post(BASEURL,parameters,headers).success(function (response) {
              //  cookie.put
              // console.log('response::', {sessionid,token,session,user_data}
             $cookies.put(response.session_name,response.token); //
              console.log(response.session_name,response.token);
              localStorage.setItem('sessid',response.sessid); // locastorage 
              localStorage.setItem('token',response.token);
              console.log(response);
               return callback(response); //call this  on the controller
            });
       }

也许可以尝试将"cookie:"改为"xsrfCookieName"并提供cookie名称。它应该使用它所包含的令牌

var headers = {'Content-Type':'application/json','xsrfCookieName':'cookieName'};

希望有所帮助