在PHP中使用CURL通过REST API在JIRA中添加问题


using CURL in PHP to add an issue in JIRA via REST API

我正在尝试构建一个应用程序,该应用程序将使用REST API向JIRA写入问题,我试图使用CURL在PHP中实现它,但我收到一个错误,告诉我"指定的HTTP方法不允许用于请求的资源(方法不允许)。"你能看看并告诉我我做错了什么吗?:

 <?php
$handle=curl_init();
$headers = array(
    'Accept: application/json',
    'Content-Type: application/json',
    'Authorization: Basic YWRtaW46eWFoYWxh'
);
$data = <<<JSON
{
    "fields": {
       "project":
       { 
          "key": "SYNC"
       },
       "summary": "No REST for the Wicked.",
       "description": "Creating of an issue using ids for projects and issue types using the REST API",
       "issuetype": {
          "name": "Bug"
       }
   }
}
JSON;

curl_setopt_array(
$handle,
array(
CURLOPT_URL=>'http://localhost:8084/rest/api/2/issue/',
CURL_POST=>true,
//CURLOPT_HTTPGET =>true,
CURLOPT_VERBOSE=>1,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_RETURNTRANSFER=>true,
CURL_HEADER=>false,
CURLOPT_HTTPHEADER=> $headers,
//CURLOPT_USERPWD=>"admin:yahala"
//CURLOPT_CUSTOMREQUEST=>"POST"
)
);
$result=curl_exec($handle);
$ch_error = curl_error($handle);
if ($ch_error) {
    echo "cURL Error: $ch_error";
} else {
    echo $result;
}
curl_close($handle);


?>

我认为是CURLOPT_POST,而不是CURL_POST。由于CURLOPT_POST没有正确设置,它可能会默认为get,这是该方法不允许的。