Tôi muốn sử dụng API REST Jira, nhưng đã không thành công.Tiêu thụ API REST Jira
Các trang web cung cấp cho Jira URL yêu cầu sau đây:
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
Và đây là mảng json, được đặt trên một tập tin gọi là collector.json:
"fields": [
{
"project":
{
"key": "ATL"
},
"summary": "REST ye merry TEST.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Task"
}
}
]
}
Sau đây là mã:
<?php
include_once "collector.php";
$jiraValues = jsonArray("collector.json");
$jira_url = "http://jira.howareyou.org:8091/rest/api/2/issue/createmeta";
$jiraString = json_encode($jiraValues);
$request = curl_init($jira_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($request, CURLOPT_ENCODING, "");
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $jiraString); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
curl_setopt($request, CURLOPT_URL, $jira_url);
$json_raw = curl_exec($request); // execute curl post and store results in $json_raw
curl_close($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$jira_response = json_decode($json_raw, TRUE);
print_r($jira_response);
Khi tôi chạy nó, Không có gì xảy ra. Tôi không nhận được phản hồi.
Tôi đã tìm thấy số here và thay thế thông tin bằng thông tin hợp lệ của tôi.
Bạn có nhận được phản hồi từ 'cURL' req không? cũng chỉ cần thử in '$ json_raw' để gỡ lỗi – Pogrindis
Và' nhiều thứ nữa, sử dụng 'echo' JSON trở lại người gọi thay vì' print_r' – Pogrindis
@Pogrindis tôi đã cố gắng lặp lại nó, vẫn không có kết quả. Tôi không chắc chắn những gì cần phải được thay thế trong đó cURL req. Lần đầu tiên tôi xử lý nó – kya