我使用Java来获取测试用例信息。我使用AuthenticateLoginLogoutExample
代码作为参考。我能够对用户进行身份验证,但当我使用 GET 方法检索简单时,我收到 HTTP 401 状态代码通过REST API获取测试用例信息等信息。
答案 0 :(得分:0)
获取HTTP 401状态代码是正常的。事实上,您可以ping服务器。此外,尝试使用" {Host} / qcbin / rest / is-authenticated"捕获响应。使用" http get"方法。您将在Documentation中的Rest Connector类中找到http get methond。
答案 1 :(得分:0)
如果您使用AuthenticateLoginLogoutExample作为参考,则应该没问题。
您收到回复的可能原因:
答案 2 :(得分:0)
HP有自己需要使用的base64encoder.java类。你不能使用java中标准的那个。你必须使用他们的版本。我得到了相同的401错误,直到找到他们的编码器类。
public class Base64Encoder {
private final static char[] ALPHABET =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static int[] toInt = new int[128];
static {
for (int i = 0; i < ALPHABET.length; i++) {
toInt[ALPHABET[i]] = i;
}
}
/**
* Translates the specified byte array into Base64 string.
*
* @param buf the byte array (not null)
* @return the translated Base64 string (not null)
*/
public static String encode(byte[] buf) {
int size = buf.length;
char[] ar = new char[((size + 2) / 3) * 4];
int a = 0;
int i = 0;
while (i < size) {
byte b0 = buf[i++];
byte b1 = (i < size) ? buf[i++] : 0;
byte b2 = (i < size) ? buf[i++] : 0;
int mask = 0x3F;
ar[a++] = ALPHABET[(b0 >> 2) & mask];
ar[a++] = ALPHABET[((b0 << 4) | ((b1 & 0xFF) >> 4)) & mask];
ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask];
ar[a++] = ALPHABET[b2 & mask];
}
switch (size % 3) {
case 1:
ar[--a] = '=';
case 2:
ar[--a] = '=';
}
return new String(ar);
}
}
答案 3 :(得分:0)
尽管已正确记录了文档,但不幸的是,我无法从microfocus的说明中推断出正在运行的代码段: https://admhelp.microfocus.com/alm/en/12.60/api_refs/REST/Content/REST_API/Authenticate_LWSSO.html#alm_authenticate_Authentication
从11迁移到12.60后,我无法在质量管理体系中读取或更新我的测试,如果我们分享它对我的工作方式,我将在《基督的光辉》中得以实现:
Map<String, String> map = new HashMap<String, String>();
map.put("Authorization", "Basic " + Base64.getEncoder().encodeToString("$userX:$passwordY".getBytes() )) ;
map.put("Content-Type", "application/json");
String loginUrl = "http://qc/qcbin/api/authentication/sign-in" ;
response = null ;
try
{
response = con.httpGet( loginUrl , "" , map ) ;
}
catch (Exception e )
{
fail(e.getMessage() );
}
functions.method_log(String.valueOf( response.getStatusCode() + response.toString() ) ); //shoudl be empty, like the manual in a browser, an empty page is returned
loginUrl = "http://qc/qcbin/rest/domains/$DOMAIN/projects/$PROJECT/tests/?fields=id,name,user-04&query={user-04["+testUniqueIdentifier+"]}" ;
try
{
response = con.httpGet( loginUrl , "" , map ) ;
}
catch (Exception e )
{
log(e.getMessage() );
}
log(String.valueOf( response.getStatusCode() + response.toString() ) );
所以这是一个简单的2个连续GET。 可以考虑在最后添加登出,这里不再赘述。