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;
}];
1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.