使用Rally API使用PHP和curl创建新缺陷
我正在使用PHP和curl,并试图在Rally中创建一个缺陷使用Rally API使用PHP和curl创建新缺陷,rally,Rally,我正在使用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
<?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行错误:Open quote
与元素类型ref关联的属性{1}应为
当我打印时,我看到:
SimpleXMLElement对象[@attributes]=>Array[rallyAPIMajor]=>1[rallyAPIMinor]=>29[Errors]=>SimpleXMLElement对象[OperationResultError]=>无法将输入流解析为XML文档:第1行错误:与元素类型ref关联的属性{1}需要打开引号。[警告]=>SimpleXMLElement对象
我希望看到类似的示例:
错误消息听起来好像ref有问题,ref是错误的一部分。有人知道我做错了什么吗?谢谢你的帮助。我从
到
这似乎起到了作用 所有者元素的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]"...
<Owner ref="https://rally1.rallydev.com/slm/webservice/1.29/user/[USERID]"...