使用jquery / axios获取OAuth2访问令牌

时间:2018-12-05 13:27:31

标签: ajax oauth-2.0 axios postman access-token

enter image description here

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

使用ajax:

 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);
      });

1 个答案:

答案 0 :(得分:0)

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