angularjs – 具有授权令牌头的angular $http GET请求

前端之家收集整理的这篇文章主要介绍了angularjs – 具有授权令牌头的angular $http GET请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用angular $http.get复制这个卷曲,
  1. curl -H "Accept: application/json" http://localhost:3000/posts -H 'Authorization: Token token="1111"'

但我不确定如何正确设置角度标题

这是我试过的方式,

  1. app.controller('newsCtrl',function($http,$scope){
  2. $scope.news =[];
  3. $http.get('http://localhost:3000/posts.json',{
  4. headers: {"Authorization": "Token[token]=1111"}).success(function(response){
  5. console.log(response)
  6. })
  7. })

那么如何正确设置标题

谢谢
ps:我没有使用基本身份验证.

如果您希望Authorization标头包含Token token =“1111”,那么这应该可行.看起来您的括号也不匹配.
  1. $http.get('http://localhost:3000/posts.json',{
  2. headers: {
  3. "Authorization": 'Token token="1111"'
  4. }
  5. }).success(function(response){
  6. console.log(response)
  7. });

猜你在找的Angularjs相关文章