javascript - 如何在 Angular js 中的 http 请求中发送 header 数据

标签 javascript html ajax angularjs

在尝试访问安全的 Api 时,我需要在我的 Angular http 请求中发送 header 数据

JavaScript 代码:

$http.post('http://localhost/api/validate', user).success(function () {
        $scope.reset();
        $scope.activePath = $location.path('/');

如何在此请求中发送 header 数据?

最佳答案

   //store the header data in a variable 
    var headers = { 'Authorization': authToken };

    //Add headers with in your request
    $http.post('http://localhost/api/validate',user, { headers: headers } ).success(function() 

关于javascript - 如何在 Angular js 中的 http 请求中发送 header 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20326514/

相关文章:

javascript - 如何防止重新获取AJAX数据?

javascript - JSDoc,引用函数描述中的标识符

javascript - 使用后台页面的跨域XMLHttpRequest

javascript - 如何将值从 javascript 传递到 html?

PHP - html 文本的 substr

javascript - javascript 中的responseText 遇到困难

ajax - 对于仅 AJAX URL 的非 AJAX 请求,我应该返回什么状态代码?

javascript - 客户关系管理 : Show all notes on the form instead of lazy-loading

javascript - 获取屏幕坐标的css

html - 如何在父 DIV 上显示子 DIV(绝对、隐藏)?