简体   繁体   中英

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

I'm trying to build an app that will write an issue to JIRA using REST API, I tried to implement it in PHP using CURL but i get an error telling me "The specified HTTP method is not allowed for the requested resource (Method Not Allowed)." can you take a look and tell me what am i doing wrong?:

 <?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);




?>

I think it's CURLOPT_POST, not CURL_POST. Since CURLOPT_POST didn't correctly get set, it will probably default to GET which isn't allowed for that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM