【问题标题】:Using the Rally API to create a new defect using PHP and curl使用 Rally API 使用 PHP 和 curl 创建新缺陷
【发布时间】:2011-12-30 20:38:00
【问题描述】:

我正在使用 PHP 和 curl 并试图在 Rally 中创建一个缺陷。

<?php
define('XML_POST_URL', 'https://rally1.rallydev.com/slm/webservice/1.29/defect/create');

/**
 * Initialize handle and set options
 */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_USERPWD, '[USERNAME]:[PASSWORD]');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, '<Defect> <Description>blah blah blah</Description> <Name>my defect</Name> <Priority>None</Priority> <ReleaseNote>false</ReleaseNote> <Severity>Major Problem</Severity> <State>Open</State> <Owner ref=\"https://rally1.rallydev.com/slm/webservice/1.29/user/[USERID]\"/> </Defect>');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));

$result = curl_exec($ch);

/**
 * Check for errors
 */
if ( curl_errno($ch) ) {
    $result = 'cURL ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
    echo "ERROR! " . $result;
} else {
    $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
    switch($returnCode){
        case 200:
            break;
        default:
            $result = 'HTTP ERROR -> ' . $returnCode;
            break;
    }
}

curl_close($ch);

$xml_parser = xml_parser_create();

xml_parse($xml_parser, $result);
$returnXML = new SimpleXMLElement($result);
echo "<br>" . $returnXML->asXML();

?>

在尝试打印 returnXML 时,出现以下错误:

无法将输入流解析为 XML 文档:第 1 行出错:打开引用 应为与元素类型“ref”关联的属性“{1}”。

当我执行 print_r 时,我看到了这个:

SimpleXMLElement 对象([@attributes] => 数组([rallyAPIMajor] => 1 [rallyAPIMinor] => 29)[Errors] => SimpleXMLElement 对象([OperationResultError] => 无法将输入流解析为 XML 文档:错误第 1 行:与元素类型“ref”关联的属性“{1}”需要打开引号。) [警告] => SimpleXMLElement Object ())

我希望看到与此示例类似的内容:https://rally1.rallydev.com/slm/doc/webservice/rest_xml.jsp

错误消息听起来像是 ref 有问题,它是 .有谁知道我做错了什么?感谢您的帮助。

【问题讨论】:

    标签: rally


    【解决方案1】:

    我把"&lt;Owner ref=\"https://rally1.rallydev.com/slm/webservice/1.29/user/[USERID]\"/&gt;改成了

    <Owner user/[USERID]/>
    

    这似乎成功了!

    【讨论】:

      【解决方案2】:

      “Owner”元素的“ref”属性中的双引号字符前有一个不需要的斜杠。

      <Owner ref=\"https://rally1.rallydev.com/slm/webservice/1.29/user/[USERID]\"...
      

      应该是:

      <Owner ref="https://rally1.rallydev.com/slm/webservice/1.29/user/[USERID]"...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-14
        • 1970-01-01
        • 2019-05-28
        • 2013-07-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多