gpt4 book ai didi

javascript - 无法发送包含特殊字符的密码(用空格代替)

转载 作者:行者123 更新时间:2023-11-30 17:15:40 24 4
gpt4 key购买 nike

我需要发送包含特殊字符的密码。例如:包含 abc+ 的密码在服务器端以 abc(space) 结束,这是错误的,打破了前面的大象。服务器是无罪的,因为我已经检查了网络并且 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';

关于javascript - 无法发送包含特殊字符的密码(用空格代替),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26167402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com