gpt4 book ai didi

javascript - 如何使用rest api javascript : automatic login访问hp alm

转载 作者:行者123 更新时间:2023-12-03 06:44:31 27 4
gpt4 key购买 nike

我只想通过 REST API 在浏览器(IE11、Firefox、Chrome)中通过本地编写的 javascript 访问 ALM,但无法登录。我尝试使用How to access HP ALM using REST and local javascript?中显示的代码,但总是有相同的错误:选项https://alm.....net/qcbin/authentication-point/authenticate 401(SecurityContext 中未找到 Authentication 对象)

也许问题是,我不知道如何

submit my credentials via XML

如链接中所述。你能帮我一下吗?

我的代码是:

function signinTest() {var auth = btoa(name + ":" + password);
$.ajax({
type: "POST",
url: 'https://alm.....net/qcbin/authentication-point/authenticate',
headers: {
"Authorization": "Basic " + auth
},
xhrFields: {
withCredentials: true
},
success: function (data) {
console.log("succes " + data);
},
error: function (data) {
console.log("error ");
console.log(data);
}
});

}

最佳答案

看来你已经混了

/authentication-point/alm-authenticate

/authentication-point/authenticate

REST 资源。

如果您想使用 XML 中的凭据登录,则需要使用 alm-authenticate 资源(请参阅 alm-authenticate doc )。

对于身份验证,您需要在 header 中发送用户信息并使用 GET 方法(请参阅 Authenticate doc )。

<小时/>

使用datacontentType在POST中通过Ajax发送XML。例如:

function signinTest() {var auth = btoa(name + ":" + password);
$.ajax({
url: 'https://alm.....net/qcbin/authentication-point/alm-authenticate',
data: "<alm-authentication><user>USERNAME</user><password>PASSWORD</password></alm-authentication>",
type: "POST",
contentType: "text/xml",
...

关于javascript - 如何使用rest api javascript : automatic login访问hp alm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37804422/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com