AJAX 401(未经授权)

在这里

我正在使用 ajax 来使用 Web 服务。

我的第一个请求是 POST 以获取身份验证令牌。(它正在工作。)但第二个请求显示“401(未经授权)”。这里可能有什么问题?

附注。我在 Chrome 上使用 CORS 扩展。如果我禁用它,我会得到“请求的资源上不存在‘Access-Control-Allow-Origin’标头”

当我在 Postman(禁用 SSL)上使用相同的令牌时,我的请求成功。同样的标记也适用于 python "requests.get(urlShow, headers=bpHeader, verify=False)"。

$.ajax({
type: 'POST',
url: 'url',
data: {"authType" : "password", "username" : "<username>", "password" : "<password>", "tenant" : "<tenant>"},
success: function(bpResponse){
    var bpAuth = "Bearer " + bpResponse.token;
    console.log(bpAuth);
    $.ajax({
        type: "GET",
        url: 'url',
        headers: {"Accept": "application/json", "Authorization": bpAuth},
        success: function(bpResources){
            console.log(bpResources);
        }
    });
  }
});

这是我得到的控制台日志:

在此处输入图片说明

在这里

只需使用以下命令运行 chrome:

"PATH:\chrome.exe" --user-data-dir --disable-web-security --ignore-certificate-errors --ignore-urlfetcher-cert-requests

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章