是否有人使用PHP处理HP ALM API?
我从qcbin / api / authentication / sign-in API
获取cookie但是当我尝试将这些cookie发送到其他后续API时,它会返回我未经过身份验证的httpcode 401.
此外,我正在使用qcbin / authentication-point / authenticate API和qcbin / api / site-session API来获取和维护会话。
我的代码如下:
$ url =“https://myhost/qcbin/api/authentication/sign-in”; $ credentials = $ user。 ':'。 $密码; $ headers = array(“GET /HTTP/1.1","Authorization:Basic”.base64_encode($ credentials));
curl_setopt($qc, CURLOPT_URL, $url);
curl_setopt($qc, CURLOPT_HTTPGET,1);
curl_setopt($qc, CURLOPT_HTTPHEADER, $headers);
curl_setopt($qc, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($qc);
$response = curl_getinfo($qc);
然后我试图获取测试集文件夹:
$ folder_name =“folder_name”; $ safe_name = rawurlencode($ folder_name); $ url =“https://myhost/qcbin/rest/domains/NETWORKS_QUALITY/projects/NETWORKS/test-set-folders?query= {name ['”。 $ safe_name。 “']}”;
$qc = curl_init();
curl_setopt($qc, CURLOPT_URL, $url);
//curl_setopt($qc, CURLOPT_HTTPHEADER, $headers);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($qc, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($qc, CURLOPT_COOKIE,$ckfile);
curl_setopt($qc, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($qc, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($qc, CURLOPT_VERBOSE, true);
$result = curl_exec($qc);
$response = curl_getinfo($qc);
this response returns me httpcode 401 instead of 200. Please help me if anybody worked on this before.
谢谢 Biswajit Jena
答案 0 :(得分:0)
尝试了解您的查询....您是否从认证中获得了200次成功?
我正在使用名为“requests”的python模块的REST-API。 如果您查看REST API库,您应该在标题中发回cookie :-)在自动化中,您应该每次查看标题(cookie)并使用它来回复它。
甚至不需要某些版本的QC ALM中的/HTTP/1.1。此外,在标题中,您必须指定其他参数,例如,如果您发送xml或json文件格式,等等。
Content-Type":"application/xml",
"KeepAlive":"true",
"Authorization":"Basic ",
"QCSession" : None,
"Cookie": None
请看一下QC ALM库,但我希望我有你的观点:-)不幸的是,我不能帮助太多,但我看不到发送到服务器的正确标题。
答案 1 :(得分:0)
是的,我得到了解决方案。 只有所需的CURL选项才能传递给任何CURL调用。
所以我只提出以下选项,它将http_code作为200返回给我,数据也是如此。无需编写不必要的CURL选项。
curl_setopt($qc, CURLOPT_URL, $url);
curl_setopt($qc, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);
谢谢