获取http post请求正文AngularJS

时间:2015-10-14 07:33:08

标签: javascript angularjs http post request

我想知道如何在AngularsJS中获取HTTP POST请求的正文。

事实是,我有一个网站向mywebsite发布一个http请求,其中包含我希望在我的角度应用程序中获取和处理的信息。

有人有办法解决这个问题吗?在角度上,我只能成功获得请求的参数而不是身体。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以在浏览器控制台中打印完整的请求和响应。

angular.module('interceptors.httpInterceptors',[])

.factory('httpInterceptors', [function () {
  return {
    request: function (config) {
      console.log(angular.toJson(config));   
      return config;
    },
    response: function (response) {
      console.log(angular.toJson(response));
    },
    responseError: function(rejection) {
    }    

  };
}])

.config(['$httpProvider', function ($httpProvider) {
  $httpProvider.interceptors.push('httpInterceptors');
}]);