0

How to encode both content and URL of any HTTP request in AngularJs?

I came through these solutions, but they are not enough for me:

for encoding only one request url : $http.get(encodeURI('your web request url'))

for content of request:

$httpProvider.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$httpProvider.defaults.transformRequest = [function(data, headers) {
    return angular.isobject(data) && string(data) !== '[object file]' ? jquery.param(data) : data;
}];
Aliunco
  • 399
  • 2
  • 9
  • http://stackoverflow.com/a/16706920/1898397 looks relevant here. http://stackoverflow.com/a/14512986/1898397 also this one – Tarun Gupta Aug 24 '15 at 08:37

2 Answers2

0

You can write a custom $http interceptor. Here you can transform/edit/customize every request, response as well as handling requestErrors and responseErrors

more information: https://docs.angularjs.org/api/ng/service/$http#interceptors

Johannes Ferner
  • 718
  • 7
  • 15
0

herre is The Solution I've used :

var module = angular.module('youApp');
module.factory('urlUpdater', function() {
    var urlUpdaterConfig = {
        request: function(requestObj) {
            // do whateveerrrrrrrr you want with request object
            return requestObj;
        }
    };
    return urlUpdaterConfig;
});
module.config(['$httpProvider', function($httpProvider) {
    $httpProvider.interceptors.push('urlUpdater');
}]);
Aliunco
  • 399
  • 2
  • 9