久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

angular.js - 后端基于JWT驗證,Angular post 請求如何攜帶token?

瀏覽:203日期:2024-09-14 11:09:41

問題描述

當用戶成功登錄后獲取后端返回的token

userService.loginUser(user).then(function(response) { $cookies.put('token', response.token) ...

然后,更新個人信息時,如何攜帶這個token呢?

token = $cookies.get('token')console.log(token)studentService.edit(token).save({studentId: $scope.student.id}, student, function(response) {console.log(response)

studentService

angular.module(’app’) .factory(’studentService’, [’$resource’,function($resource) { return {detail: function() { return $resource(’/api/student/:studentId/ ’, {studentId: ’@studentId’ })},edit: function(token) { return $resource(’/api/student/:studentId/edit/ ’, {studentId: ’@studentId’ },{headers: { ’auth-token’: token }})} }} ]);

angular.js - 后端基于JWT驗證,Angular post 請求如何攜帶token?

angular.js - 后端基于JWT驗證,Angular post 請求如何攜帶token?

我是這樣做的,但是仍然顯示驗證不通過。

問題解答

回答1:

{withCredentials:true} 科普連接

回答2:

謝邀,手機上不方便給發(fā)送具體文章鏈接。主要給你思路哈。應該登錄后,每個請求都需要帶token上去。一般會通過添加自定義請求頭,然后AngularJS 1.x 有提供攔截器來實現(xiàn)這個功能哈。另外建議你也查找一下,MDN CORS的相關(guān)資料及$resource相關(guān)文檔。國外有很多AngularJS 1.x與JWT的應用示例,建議你Google搜索一下。

回答3:

用angularjs-jwt,在每個請求頭上加上token,參考:github地址https://github.com/auth0/angu...

主站蜘蛛池模板: 洱源县| 和平区| 吉首市| 德州市| 红桥区| 怀远县| 东宁县| 长顺县| 扶沟县| 松原市| 平凉市| 上饶市| 磐石市| 新兴县| 大港区| 蒙城县| 小金县| 屏东市| 天全县| 克东县| 孝昌县| 庆城县| 西贡区| 延寿县| 北流市| 浏阳市| 皋兰县| 枣强县| 额济纳旗| 乌苏市| 环江| 双江| 宜君县| 贺兰县| 华阴市| 临海市| 波密县| 平远县| 安平县| 蕉岭县| 抚松县|