QC ALM REST使用REST API创建缺陷

时间:2015-08-14 17:03:48

标签: rest qc hp-quality-center hp-alm

我正在尝试使用rest api

在QC中打开一个新缺陷

我的代码如下所示

createxml ='<Entity Type="defect">
<Fields>
     <Field Name="user-15">
          <Value>Development</Value>
     </Field>' ;

$qc = curl_init();
// create a cookie file
$ckfile = tempnam ("/tmp", "CURLCOOKIE");

// The authentication is done and also checks are done and after below code is executed to create a new defect in QC

$url ="http://host/qcbin/rest/domains/STANDARD_STRUCT/projects/Releases/defects/" ;

curl_setopt($qc, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($qc, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($qc, CURLOPT_HTTPHEADER, Array("Accept: application/xml"));
curl_setopt($qc, CURLOPT_URL, $url);
curl_setopt($qc, CURLOPT_POST, 1);
curl_setopt($qc, CURLOPT_POSTFIELDS,$createxml);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($qc);

if(curl_errno($qc))
    print curl_error($qc) ;
else
    curl_close($qc) ;

echo $result ; `

注意:使用未定义的常量http_code - 假设&#39; http_code&#39;在第150行的C:\ xampp \ htdocs \ createdef.php中,没有创建响应“

我无法弄清楚导致问题的原因。

1 个答案:

答案 0 :(得分:1)

我能看到的两个错误是:

1)

 createxml ='<Entity Type="defect">
    <Fields>
         <Field Name="user-15">
              <Value>Development</Value>
         </Field>' ;

- &GT;你没有关闭菲尔兹。至少可以添加对xml的正确检查 来自你我的意思是简短的xml创建。

2)删除&#39; /&#39;在命令行的末尾签名。你不需要那个。

如果创建,则从ALM API回复代码201。 我知道很长一段时间过去了,但是将来会有所帮助!

请检查并度过愉快的一天。

相关问题