如何在angularjs中将cookie作为header传递给使用drupal的远程应用程序[403禁止]
How to pass cookie as header in angularjs to a remote application that uses drupal [403 Forbidden]
你好,我试图使一个$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'};
希望有所帮助
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- angular 1.5应用程序中的导航栏
- 在Web应用程序中使用Highcharts javascript
- angularjs+rails应用程序中未显示模板
- 使用acess代币登录Facebook,并通过网络应用程序离线发布
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 在phonegap应用程序内部重定向不起作用
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- Node.js正在更改应用程序以使用集群模块
- 在openshift node js应用程序中获取请求
- 如何在angularjs应用程序中解析Drupal JSON数据
- 如何在angularjs中将cookie作为header传递给使用drupal的远程应用程序[403禁止]