[英]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)." 我正在尝试构建一个使用REST API向JIRA写一个问题的应用程序,我尝试使用CURL在PHP中实现它,但是我收到错误告诉我“所请求的资源不允许指定的HTTP方法(方法不是允许的)。” 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. 我认为它是CURLOPT_POST,而不是CURL_POST。 Since CURLOPT_POST didn't correctly get set, it will probably default to GET which isn't allowed for that method. 由于CURLOPT_POST未正确设置,因此可能默认为GET,该方法不允许这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.