国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

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

問題描述

當(dāng)用戶成功登錄后獲取后端返回的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ā)送具體文章鏈接。主要給你思路哈。應(yīng)該登錄后,每個請求都需要帶token上去。一般會通過添加自定義請求頭,然后AngularJS 1.x 有提供攔截器來實現(xiàn)這個功能哈。另外建議你也查找一下,MDN CORS的相關(guān)資料及$resource相關(guān)文檔。國外有很多AngularJS 1.x與JWT的應(yīng)用示例,建議你Google搜索一下。

回答3:

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

主站蜘蛛池模板: 汪清县| 嵊州市| 济南市| 丰都县| 乌鲁木齐市| 麟游县| 彭山县| 南江县| 崇明县| 平果县| 富裕县| 连城县| 高唐县| 武汉市| 肃宁县| 乐亭县| 巴林左旗| 张北县| 小金县| 西平县| 乐安县| 舟曲县| 通渭县| 庆安县| 博野县| 友谊县| 柘城县| 封丘县| 施甸县| 三亚市| 乌拉特前旗| 信宜市| 衢州市| 历史| 海城市| 汝城县| 扬州市| 外汇| 象州县| 辽阳市| 菏泽市|