我正在使用 HP-ALM 12.01,它似乎充满了问题。我目前无法更新到另一个版本。
我正在尝试访问其余 api 以从 JUnit 自动上传测试结果。我正在使用此处显示的基础架构 (示例应用程序 -> 基础架构)。从中,我的连接脚本将 base64 编码的登录信息传递给身份验证点/身份验证,并且我正在检索有效的 LWSSO cookie。但是,当我使用此 cookie 连接到 rest/site-session 以接收我的 QCSession cookie 时,我收到 411 Length Required 错误。我试图将 Content-Length 硬编码到标题中,如此处所示
public void GetQCSession(){
String qcsessionurl = con.buildUrl("rest/site-session");
Map<String, String> requestHeaders = new HashMap<String, String>();
requestHeaders.put("Content-Type", "application/xml");
requestHeaders.put("Accept", "application/xml");
requestHeaders.put("Content-Length", "0");
try {
Response resp = con.httpPost(qcsessionurl, null, requestHeaders);
con.updateCookies(resp);
System.out.println(resp.getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
}
这没有用。我还尝试修改基础结构以自动注入 Content-Length 标头,如下所示
private void prepareHttpRequest(
HttpURLConnection con,
Map<String, String> headers,
byte[] bytes,
String cookieString) throws IOException {
String contentType = null;
//attach cookie information if such exists
if ((cookieString != null) && !cookieString.isEmpty()) {
con.setRequestProperty("Cookie", cookieString);
}
//send data from headers
if (headers != null) {
//Skip the content-type header - should only be sent
//if you actually have any content to send. see below.
contentType = headers.remove("Content-Type");
Iterator<Entry<String, String>>
headersIterator = headers.entrySet().iterator();
while (headersIterator.hasNext()) {
Entry<String, String> header = headersIterator.next();
con.setRequestProperty(header.getKey(), header.getValue());
}
}
// If there's data to attach to the request, it's handled here.
// Note that if data exists, we take into account previously removed
// content-type.
if ((bytes != null) && (bytes.length > 0)) {
con.setDoOutput(true);
//warning: if you add content-type header then you MUST send
// information or receive error.
//so only do so if you're writing information...
if (contentType != null) {
con.setRequestProperty("Content-Type", contentType);
}
OutputStream out = con.getOutputStream();
out.write(bytes);
out.flush();
out.close();
con.setRequestProperty("Content-Length", Integer.toString(bytes.length));
} else {
con.setRequestProperty("Content-Length", "0");
}
}
这也不起作用。请注意, setRequestProperty 只是对MessageHeader执行 .set(key, value)
有没有人处理过这个问题或知道如何解决它?
请注意,邮递员不会出现这些问题。所有 4 个 cookie 都是在站点会话发布后生成的。