我想转换ajax卷曲。
curl localhost:8080 / oauth / token -h foo:bar -d grant_type = password -d username = [email protected] -d password = 1
上面的命令成功。
但是ajax失败了......
$.ajax({
url: 'http://localhost:8080/oauth/token',
type: 'POST',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic' + btoa('foo:bar'));
},
data: {
grant_type: 'password',
username: '[email protected]',
password: '1'
},
complete: function(result) {
console.log('complete', result);
},
success: function(result) {
console.log('success', result);
},
error: function(result) {
console.log('error', result);
}
});
我转换为ajax,出现以下错误。
预检的响应具有无效的HTTP状态代码401
responseJSON:未定义
问题是什么?
我找到了解决方案
修改OauthServer
更改“source.registerCorsConfiguration(”/ **“,configAutenticacao);” to“source.registerCorsConfiguration(”/ oauth / token“,configAutenticacao);”在corsFilterRegistrationBean中