可以't发送包含特殊字符的密码(用空格代替)

Can't send password containing special characters(replaced with space)

本文关键字:密码 空格 特殊字符 包含 可以      更新时间:2023-09-26

我需要发送包含特殊字符的密码。例如:包含abc+的密码最终在服务器端变成abc(空格),这是错误的,破坏了前面的大象。服务器是无罪的,因为我已经检查了网络,angular确实用空格而不是"abc+"发送到服务器"abc"。所以问题出在客户端代码上。

 login: function (param) {
                        var data,
                            config = {
                                headers: {
                                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
                            },
                            ignoreAuthModule: 'ignoreAuthModule'
                        };
                    data = 'j_username=' + param.username + '&j_password=' + param.password + '&_spring_security_remember_me=' + param.rememberMe + '&submit=Login';
                    if (!angular.isUndefined(param.service)) {
                        data += '&service=' + param.service;
                    }
                    $http.post('app/authentication', data, config).success(
                        function (data, status, headers, config) {
                            $rootScope.registrationSuccess = false;
                            $rootScope.authenticationError = false;
                            $rootScope.userLocked = false;
                            if (param.success) {
                                param.success(data, status, headers, config);
                            }
                        }
                    ) ...

当我调试代码j_password时,它实际上有"abc+"。我想有些配置是错误的。请帮助可怜的java开发人员。

您应该使用encodeURIComponent对参数进行编码。例如,

data = 'j_username=' + encodeURIComponent(param.username) + '&j_password=' + encodeURIComponentparam.password) + '&_spring_security_remember_me=' + encodeURIComponent(param.rememberMe) + '&submit=Login';