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

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:212日期: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:

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

回答3:

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

主站蜘蛛池模板: 枝江市| 宜兴市| 盈江县| 武威市| 馆陶县| 庆云县| 搜索| 湖南省| 托克逊县| 铜梁县| 当阳市| 江陵县| 新河县| 平江县| 慈利县| 社会| 蚌埠市| 宿迁市| 正阳县| 交城县| 渭源县| 麻城市| 永新县| 囊谦县| 馆陶县| 图片| 长武县| 融水| 马鞍山市| 金堂县| 北流市| 赤壁市| 阳信县| 六枝特区| 孟州市| 曲阳县| 浑源县| 乌什县| 慈溪市| 辽中县| 体育|