ajax - 使用 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);
});
解决方案
其 SSL 证书错误,您需要首先在地址栏中打开 URL 并将证书导入浏览器。
推荐阅读
- python - 将系列从 pandas 转换为 pyspark:需要使用“groupby”和“size”,但 pyspark 会产生错误
- javascript - 如何在本机反应中对齐项目?
- windbg - “检测到 PNP/INF 版本与图形适配器上的 KMD 文件版本不匹配”
- pointers - 为什么在执行指针追逐时这条跳转指令如此昂贵?
- php - 在 WooCommerce 中单击“添加到购物车”按钮后询问电子邮件或电话
- java - Blazegraph 中的词汇创建
- javascript - 通过动态变量更新方法不起作用
- c++ - MysteryLinkedList 使用笔和纸追踪代码
- reactjs - 我可以为自定义钩子提供 react-hooks/exhaustive-deps 吗?
- php - 为什么我的 Laravel 6 CMS 没有生成 URL 的站点地图