我试图使用angular $http.get复制这个卷曲,
ps:我没有使用基本身份验证.
curl -H "Accept: application/json" http://localhost:3000/posts -H 'Authorization: Token token="1111"'@H_404_3@但我不确定如何正确设置角度标题 @H_404_3@这是我试过的方式,
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) }) })@H_404_3@那么如何正确设置标题? @H_404_3@谢谢
ps:我没有使用基本身份验证.
如果您希望Authorization标头包含Token token =“1111”,那么这应该可行.看起来您的括号也不匹配.
$http.get('http://localhost:3000/posts.json',{ headers: { "Authorization": 'Token token="1111"' } }).success(function(response){ console.log(response) });