我试图使用Java中的Rest访问QC 11。
我正在遵循惠普提供的手册中的API参考。以下是登录身份验证的基本步骤。
非Web应用授权客户端查询经过身份验证的资源,并且不发送身份验证标头.这个步骤是可选的。GET /qcbin/rest/is-身份验证
服务器拒绝请求并返回对身份验证点的引用。
HTTP/1.1 401未经授权的WWW-身份验证: LWSSO realm=http://[server]:[port]/qcbin/authentication-point
客户端向身份验证点发送有效的基本身份验证标头。
获取/qcbin/身份验证-点/身份验证授权:基本ABCDE123
服务器验证基本身份验证头,创建一个新的LW令牌,并将其作为LWSSO_COOKIE_KEY返回。
HTTP/1.1 200 OK Set-Cookie: LWSSO_COOKIE_KEY={cookie}
应用程序现在可以使用令牌访问数据和服务。在会话结束时,注销以丢弃令牌。
这是我的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坏请求从服务器输出.
我刚开始使用Java来休息。有人能帮忙吗?有使用REST和获取数据连接到ALM的示例吗?
发布于 2012-06-08 06:00:36
解决了这个问题.
问题在于base64编码!如果要将字符串转换为base64编码的字符串.如果结果大于76焦耳。它增加了新的线条!即使它少于76
所以解决办法是
encoding = encoding.replaceAll("\n", "");https://stackoverflow.com/questions/10931103
复制相似问题