2016-11-02 4 views
0

良い日、私はagular.jsでdrupalを使用するリモートアプリケーションに$ http get要求を出そうとしています。たびに、私はget要求を行う私は[annonymusユーザー]と言って403応答を取得します。私はput要求を行い、token、session_name、およびsession_idで応答を得ることができます。私の問題はです。どのようにリクエストヘッダーの一部としてクッキーを渡すかわかりません。 ** **ヘッダーとしてCookieを渡そうとしましたが、まだ403の応答があります。アドバイスが役に立ちます。私はさらに$ cookie.put( 'KEY、cookie)を使ってクッキーを保存しようとしましたが、私は同じレスポンスを得ました。drupalを使用するリモートアプリケーションにangularjsのヘッダとしてcookieを渡す方法[403 Forbidden]

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 
      }); 
     } 

答えて

0

のように見える「xsrfCookieName」を入れて、クッキー名を提供します。 トークンに含まれているトークンを使用する必要があります。

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

は、それが

+0

は、Cookieの値になるはずCOOKIENAMEないのに役立ちます願っていますか? – Percy

+0

よく、クッキーは辞書のようなものです。 キー、値 $ cookies.put(name、value) ヘッダーと同じ方法で、Cookie名を指定すると、Cookie値が設定されます。 – NiGmAx

+0

ありがとう、私はちょうどいくつかの明確化が必要でした – Percy

関連する問題