首页 > 解决方案 > 使用 jquery/axios 获取 OAuth2 访问令牌

问题描述

在此处输入图像描述

我想获得一个新的访问令牌,在邮递员中效果很好,但是当我尝试在代码中执行此操作时,我的 chrome 控制台中不断出现错误。

使用阿贾克斯:

 POST https://10.250.252.1:43002/oauth/token net::ERR_CERT_AUTHORITY_INVALID       jquery-3.3.1.min.js:2

使用 axios:

  POST https://10.250.252.1:43002/oauth/token net::ERR_CERT_AUTHORITY_INVALID       jquery-3.3.1.min.js:2

Uncaught (in promise) Error: Network Error
 at e.exports (spread.js:25)
at XMLHttpRequest.l.onerror (spread.js:25)

我使用的代码:

         $.ajax({
        method:"POST",
        url: `https://10.250.252.1:43002/oauth/token`,
        contentType:"application/json; charset=utf-8",
        data: {
            grant_type:"password",
            username:'user',
            password:'user',
            client_id:'11111111111111111',
            client_secret:'1111'
        }
        }).done(
            function(response) {
            console.log(response);
            });


      axios.request({
        url: "https://10.250.252.1:43002/oauth/token",
        method: "post",
        'content-type':'application/x-www-form-urlencoded',
        auth: {
          username: "user",
          password: "user"
        },
        data: {
          grant_type: "password",
          client_id:'11111111111111111',
          client_secret:'1111',
          scope: "public"
        }
      })
      .then(function(res) {
        console.log(res);
      });

标签: ajaxoauth-2.0axiospostmanaccess-token

解决方案


其 SSL 证书错误,您需要首先在地址栏中打开 URL 并将证书导入浏览器。


推荐阅读