gpt4 book ai didi

java - QC ALM ( QC 11) 身份验证时 REST Api 400 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:14 25 4
gpt4 key购买 nike

我正在尝试使用 Java 中的 Rest api 访问 QC 11。

我正在关注 HP 提供的手册中的 API 引用。以下是登录身份验证的基本步骤。

Non-Web Application Authorization Client queries the is-authenticated resource and sends no authentication headers. This step is optional.

GET/qcbin/rest/is-authenticated

服务器拒绝请求并返回对身份验证点的引用。

HTTP/1.1 401 未经授权的 WWW 验证:LWSSO realm=http://[server]:[port]/qcbin/authentication-point

客户端发送一个有效的基本认证头给认证 点。

GET/qcbin/authentication-point/authenticate 授权:基本 ABCDE123

服务器验证基本身份验证 header ,创建一个新的 LW-SSO token 并将其作为 LWSSO_COOKIE_KEY 返回。

HTTP/1.1 200 OK 设置 Cookie:LWSSO_COOKIE_KEY={cookie}

应用程序现在可以使用 token 访问数据和服务。在 session 结束,注销以丢弃 token 。

这是我的java代码。

DefaultHttpClient httpClient = new DefaultHttpClient();

String encoding = Base64.encodeBase64String("demoUser:demoUser123".getBytes());
HttpGet httpGet = new HttpGet("http://HOST_VALUE:PORT_VALUE/qcbin/authentication-point/authenticate");
//httpGet.setHeader("GET", "/qcbin/authentication-point/authenticate");
httpGet.setHeader("Authorization:", "Basic " + encoding);
HttpResponse response;



httpClient.getCredentialsProvider().setCredentials(
new AuthScope("proxyHost", 8080),
new UsernamePasswordCredentials("userName", "Password"));




response = httpClient.execute(httpGet);


System.out.println(response.getAllHeaders().toString());
System.out.println(response.getStatusLine().toString());
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
httpClient.getConnectionManager().shutdown();

它给我的输出是

[Lorg.apache.http.Header;@159e154 HTTP/1.1 400 Bad Request Output from Server ....

我是使用 Java 接触 REST 的新手。谁能帮忙?有使用 REST 连接到 ALM 并获取数据的示例吗?

最佳答案

解决了问题。

问题出在 base64 编码上!如果您将字符串转换为 base64 编码的字符串...如果结果大于 76 个字符。它添加了新行!即使小于 76

所以解决方案是

encoding = encoding.replaceAll("\n", "");

关于java - QC ALM ( QC 11) 身份验证时 REST Api 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931103/

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