Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 带有授权令牌头的$http GET请求_Angularjs_Ionic - Fatal编程技术网

Angularjs 带有授权令牌头的$http GET请求

Angularjs 带有授权令牌头的$http GET请求,angularjs,ionic,Angularjs,Ionic,我试图用angular$http.get复制这个旋度 curl -H "Accept: application/json" http://localhost:3000/posts -H 'Authorization: Token token="1111"' 但我不知道如何正确设置角度标题 我就是这样试的 app.controller('newsCtrl', function($http, $scope){ $scope.news =[]; $http.get('

我试图用angular$http.get复制这个旋度

curl -H "Accept: application/json" http://localhost:3000/posts -H 'Authorization: Token token="1111"'
但我不知道如何正确设置角度标题

我就是这样试的

    app.controller('newsCtrl', function($http, $scope){
      $scope.news =[];
      $http.get('http://localhost:3000/posts.json', {
        headers: {"Authorization": "Token[token]=1111"}).success(function(response){
        console.log(response)
      })
    })
那么如何正确设置标题呢

多谢各位
ps:我没有使用基本身份验证。

如果您希望授权标头包含
Token Token=“1111”
,那么这应该可以工作。看起来你的括号也不匹配

  $http.get('http://localhost:3000/posts.json', {
    headers: {
        "Authorization": 'Token token="1111"'
    }
  }).success(function(response){
    console.log(response)
  });

为什么您在Angular中使用
Token[Token]=1111
,而不是
Authorization:Token-Token=“1111”
?这实际上是我的问题,如何正确地写入头。我也试过了,
$http.get('http://localhost:3000/posts.json“,{headers:{”Authorization:Token-Token=1111“})
但仍不起作用。很抱歉,我的问题可能是重复的,但这种方法不会公开API密钥(使用开发人员工具)?是的,它会。这取决于您的用例,这可能是可接受的,也可能是不可接受的。@AnidMonsur您能否详细说明为什么会公开令牌?如果使用TLS,这仍然是正确的吗?