【问题标题】:conver to ajax to curl -> curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test@gmail.com -d password=1将 js 转换为 curl -> curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test@gmail.com -d password=1
【发布时间】:2018-06-07 17:23:37
【问题描述】:

我想将 ajax 转换为 curl。

curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test@gmail.com -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: 'test@gmail.com',
        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:未定义

有什么问题?

【问题讨论】:

    标签: ajax curl oauth token


    【解决方案1】:

    我找到了解决办法。

    修改 OauthServer

    更改 "source.registerCorsConfiguration("/**", configAutenticacao);"到 "source.registerCorsConfiguration("/oauth/token", configAutenticacao);"在 corsFilterRegistrationBean 中

    【讨论】:

      猜你喜欢
      • 2018-07-24
      • 2019-03-09
      • 2018-01-17
      • 2016-08-11
      • 2014-09-20
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多