【问题标题】:Change the request body in interceptor angular2更改拦截器 angular2 中的请求正文
【发布时间】:2019-01-29 20:49:29
【问题描述】:

如何在拦截器中更改帖子的请求正文类型?

例如我有这个对象:

{"UserName":"213243546","Password":"89876"}

我想将所有 3 更改为 e 但不仅在这个请求中我有这个,我应该在每个帖子请求中搜索它可能有或没有的每一个数据和对象并改变所有3e 都可以在angular 2 中通过克隆或HttpRequest 来做到这一点 或检查员或。 .

我已经看到this URL,但我无法从中得到太多。

【问题讨论】:

标签: angular request inspector


【解决方案1】:

你可以像这样创建一个拦截器:

app.config(['$httpProvider', function($httpProvider) {

  $httpProvider.interceptors.push(function($log, $injector, $location) {
    return({
       request: request,
       requestError: requestError,
       response: response,
       responseError: responseError
    });

   function request(config) {    

            // place your code logic inside here

            return config;
    }

    function requestError(rejection) {
        $log.debug(rejection);
        return $q.reject(rejection);  
    }
  });

}]);

然后您可以修改配置对象!

【讨论】:

    猜你喜欢
    • 2016-04-19
    • 2023-03-19
    • 2019-10-04
    • 1970-01-01
    • 2023-03-19
    • 2016-03-25
    • 2017-02-09
    • 1970-01-01
    • 2014-03-27
    相关资源
    最近更新 更多