我正在使用HP-ALM 12.01,它似乎充滿了問題。我目前無法更新到其他版本。HP ALM Rest API QCSession 411身份驗證
我想要訪問其餘api從JUnit自動上傳測試結果。我正在使用顯示here(示例應用程序 - > Infrastructure)的基礎結構。從中,我的連接腳本將base64編碼的登錄信息傳遞給authentication-point/authenticate,並且我正在檢索有效的LWSSO cookie。但是,當我使用此cookie連接到rest/site-session以接收我的QCSession cookie時,我收到了411長度要求錯誤。我試圖將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();
}
}
這沒有奏效。我也嘗試修改基礎結構以自動注入內容長度標題,如下所示
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只是一個.set(鍵,值)到MessageHeader
有沒有人處理過這個問題或知道如何解決它?
請注意,郵遞員不會發生這些問題。所有4個Cookie都是在網站會話後生成的。
@Cyrusu你不必發送內容長度以獲得QCsession cookie – Barney