2015-07-10 100 views
0

因爲我是Rest API的新手,請原諒我,如果我問任何愚蠢的問題。通過REST API在JIRA中鏈接問題

下面是我通過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

我沒有收到任何錯誤,以檢查發生了什麼問題。而且它也沒有鏈接問題。請幫忙。 – user93068

+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']); 
} 
相關問題