从 angular 中的 $http.get 访问配置 api

access config from $http.get in angular js in rest api

这是我用来在 angular js 中使用 http get 中的配置传递数据的代码。

app.controller("users", function($scope,  $http, $routeParams,    $route,$window){
$scope.role_name = $window.role_name;
  var config = {
       params: 
       {
           'session' : session['email']
       }
  }
  $http.get("http://localhost:5000/users",config   ).success(function(response){
      $scope.users = response;
  });       
});

这是剩下的代码api:

@api.route('/users', methods=['GET'])
def get_users():

    if 'session' in request.json:
        try:
            result = sys.get_users_client(request.json['session'])
        except:
            abort(503,'not logged in')
        else :
            return jsonify_list(result)

这里我如何访问配置中的参数,以便我可以使用传入的 'session'。

在 header 中传递或作为查询字符串传递,我很确定每个其余 api 都允许您访问请求 header 和请求查询字符串。通过查看您在 $http.get 中传递查询字符串的代码,因此您需要在您的 api.

中访问当前请求查询字符串

通过查看你的代码,如果它是 python 你可以获得如下查询字符串

>>> request.geturl()

>>> url = urlparse(request.geturl())
>>> url.query