angular.js - 后端基于JWT验证,Angular post 请求如何携带token?
本文介绍了angular.js - 后端基于JWT验证,Angular post 请求如何携带token?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
当用户成功登录后获取后端返回的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 }})
}
}
}
]);
我是这样做的,但是仍然显示验证不通过。
解决方案
{withCredentials:true}
科普连接
这篇关于angular.js - 后端基于JWT验证,Angular post 请求如何携带token?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文