如果我是Rest API的新手,请原谅我,如果我问任何愚蠢的问题。
以下是我通过REST API链接JIRA中的问题的脚本。它运行不正常,无法找出问题所在,因为它也没有抛出任何错误。请帮帮我,我出错了。
<?php
$restAPIURL = 'http://Company.Name/jira/rest/api/2/';
$projectsURL = $restAPIURL."issueLink/";
function callJIRAAPI($username,$password,$url,$jdata)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jdata);
$issue_list = (curl_exec($curl));
curl_close($curl);
return json_decode($issue_list,true);//print_r($arr[0]['issues']);
}
$data = array(
'type'=>'Relates',
'comment'=>"Testing linkissue Script"
);
$data['inwardIssue'][]= array("key"=>"TEST-313");
$data['outwardIssue'][]= array("key"=>"TEST-314");
$jdata = json_encode($data);
try {
echo $projectList = "<option value='-1'>--List of Links for the project--</option>";
callJIRAAPI($username,$password,$projectsURL,$jdata);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
答案 0 :(得分:0)
感谢您的帮助,我从不同的来源得到了答案。发布ref的答案。问题在于声明内容类型。
function callJIRAAPI($username,$password,$url,$jdata)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
//curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $jdata);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jdata))
);
//print_r(curl_exec($curl));
$issue_list = curl_exec($curl);
curl_close($curl);
print_r($issue_list);
return json_decode($issue_list,true);//print_r($arr[0]['issues']);
}