1

I am trying to sending some special character in header from javascript using this code:

  $scope.validatePass = function (pincode,userName) {
                httpCallConfig.headers = angular.extend(httpCallConfig.headers || {}, {
                    "Re-Authenticate-Me": "Yes"
                    , "j_username": userName
                    , "j_password": pincode
                });
                $http(httpCallConfig).then(
                    function (resps) {
                        if (resps === false) {
                            return;
                        }
                        $modalInstance.close(resps);
                    }
                    , function (data) {
                        if (data.status == 401) {
                           $log.info("faile pincode");
                        } else {
                            $log.error(data);
                            $scope.error = "other error!";
                        }
                    }
                );
            };

but getting a problem if userName contains any special characters å,ø,æ then server return 401 status. Can someone tell me how and which encoding should i need to use if i need to send special characters.

  • You don't have to use any special encoding as JavaScript strings consist of UTF-16 codepoints. For more info read http://stackoverflow.com/questions/11141136/default-javascript-character-encoding?answertab=votes#tab-top. – Gaurav Mar 22 '17 at 11:19
  • I am not getting where i need to make change(server or client) to work this –  Mar 22 '17 at 11:26
  • Please provide a working jsfiddle/codepen code snippet also read [MCVE] – Gaurav Mar 22 '17 at 11:29

1 Answers1

2

well it just need to encodeURI:

 "j_username": encodeURI(userName)