0

How can I change the request body type of post in interceptor?

For example I have this object:

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

that I want to change all 3 to e but it is not only in this request that I have this, I should search in each post request with every single data and objects that it might have or not and change all 3 to e is that possible in angular 2 to do that by clone or HttpRequest or inspector or . .

I already see this URL but I couldn't get much out of it.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
nima Sr
  • 1
  • 3
  • For Angular, not AngularJS, you can check this link: https://stackoverflow.com/questions/35498456/what-is-httpinterceptor-equivalent-in-angular2 – Carlos Jafet Neto Jan 29 '19 at 11:21

1 Answers1

0

You can create an interceptor like this:

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

}]);

You can then modify the config object!