3
我想建立一個應用程序,將使用REST API, 寫一個問題JIRA我試着用捲曲來實現它的PHP,但我得到一個錯誤告訴我「指定的HTTP方法是不允許用於所請求的資源(不允許的方法)。」你可以看看,並告訴我我做錯了什麼?:使用PHP捲曲通過REST API在JIRA添加一個問題
<?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);
?>
你必須驗證身份,才能做到這一點? – gkalikapersaud
也可以在任何數據後HTTP POST返回,如票號? – gkalikapersaud