简体   繁体   English

获取http发布请求正文AngularJS

[英]Get the http post request body AngularJS

I'm wondering how can I get the body of an HTTP POST request in AngularsJS. 我想知道如何在AngularsJS中获取HTTP POST请求的正文。

The fact is that I have a website that post an http request to mywebsite with informations in the body that I want to get and treat in my angular app. 事实是,我有一个网站将一个http请求发布到mywebsite,其中包含我想在我的有角度的应用程序中获取和处理的正文中的信息。

Is somebody has a solution to do that ? 有人有解决方案吗? In angular I only succeeded to get the params of the request but not the body. 在角度上,我仅成功获得了请求的参数,但没有成功获得主体。

Thanks. 谢谢。

You can print complete request and response in browser console. 您可以在浏览器控制台中打印完整的请求和响应。

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');
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM