如何POST到url? (使用 JIRA api 创建问题)
How to POST to a url? (create an issue using JIRA api)
我在 how to create an issue in jira via rest api?
中找到了这个答案
POST to this URL
https://<JIRA_HOST>/rest/api/2/issue/
This data:
{
"fields": {
"project":
{
"key": "<PROJECT_KEY>"
},
"summary": "REST EXAMPLE",
"description": "Creating an issue via REST API",
"issuetype": {
"name": "Bug"
}
}
}
In received answer will be ID and key of your ISSUE:
{"id":"83336","key":"PROJECT_KEY-4","self":"https://<JIRA_HOST>/rest/api/2/issue/83336"}
Don't forget about authorization. I used HTTP-Basic one.
我相信这描述了如何通过 posting 到 url.
创建问题
问题是,我不知道这实际上是如何实现的。
一个POST如何变成一个url?
这和PHP post一样吗?
数据保存在哪里?
这都是用什么语言写的?
很抱歉提出这样一个含糊的问题,这对我来说都是全新的,我什至不知道从哪里开始研究这个 >_< 任何具体的例子都会非常有用!
谢谢!
数据部分以JSON格式编写,这只是数据结构的文本表示。它为了便于阅读而缩进,但实际上可以显示为:
{"fields":{"project":{"key": ""},"summary": "REST EXAMPLE","description":"Creating an issue via REST API","issuetype":{"name":"Bug"}}}
要 POST 到 URL 并创建一个问题,您需要一个服务器端机制来首先对 Jira 进行身份验证,然后使用 HTTP POST 发送数据。
在PHP中,可以用cURL去POST或GET,或者用file_get_contents()去GET。
PHP cURL 文档在这里:
http://php.net/manual/en/book.curl.php
例如,这里有一个 PHP 创建 Jira 问题的函数(在验证之后):
public function createIssue(){
/*
Issue types:
1: Bug
3: Task
5: Sub-task
*/
$out = false;
$this->method = "POST";
$this->url = "http://10.50.25.64:8080/rest/api/2/issue/";
$this->data = array(
"fields" => array(
"project" => array("key" => $this->projectKey),
"summary" => $this->summary,
"environment" => $this->environment,
"description" => $this->description,
"issuetype" => array("id" => $this->issueType),
)
);
if (!empty($this->assignee)) $this->data['fields']['assignee'] = $this->assignee;
if (!empty($this->labels)) $this->data['fields']['labels'] = $this->labels;
foreach($this->customFields as $key => $val){
$this->data['fields'][$key] = $val;
}
$issue = $this->execCURL();
return $issue;
}
函数 execCURL() 获取 PHP 数组 ($this->data) 并使用 PHP cURL.[=12= 发送它]
希望以上内容对您有所帮助!
我在 how to create an issue in jira via rest api?
中找到了这个答案POST to this URL
https://<JIRA_HOST>/rest/api/2/issue/
This data:
{ "fields": { "project": { "key": "<PROJECT_KEY>" }, "summary": "REST EXAMPLE", "description": "Creating an issue via REST API", "issuetype": { "name": "Bug" } } }
In received answer will be ID and key of your ISSUE:
{"id":"83336","key":"PROJECT_KEY-4","self":"https://<JIRA_HOST>/rest/api/2/issue/83336"}
Don't forget about authorization. I used HTTP-Basic one.
我相信这描述了如何通过 posting 到 url.
创建问题问题是,我不知道这实际上是如何实现的。
一个POST如何变成一个url?
这和PHP post一样吗?
数据保存在哪里?
这都是用什么语言写的?
很抱歉提出这样一个含糊的问题,这对我来说都是全新的,我什至不知道从哪里开始研究这个 >_< 任何具体的例子都会非常有用!
谢谢!
数据部分以JSON格式编写,这只是数据结构的文本表示。它为了便于阅读而缩进,但实际上可以显示为:
{"fields":{"project":{"key": ""},"summary": "REST EXAMPLE","description":"Creating an issue via REST API","issuetype":{"name":"Bug"}}}
要 POST 到 URL 并创建一个问题,您需要一个服务器端机制来首先对 Jira 进行身份验证,然后使用 HTTP POST 发送数据。 在PHP中,可以用cURL去POST或GET,或者用file_get_contents()去GET。 PHP cURL 文档在这里: http://php.net/manual/en/book.curl.php
例如,这里有一个 PHP 创建 Jira 问题的函数(在验证之后):
public function createIssue(){
/*
Issue types:
1: Bug
3: Task
5: Sub-task
*/
$out = false;
$this->method = "POST";
$this->url = "http://10.50.25.64:8080/rest/api/2/issue/";
$this->data = array(
"fields" => array(
"project" => array("key" => $this->projectKey),
"summary" => $this->summary,
"environment" => $this->environment,
"description" => $this->description,
"issuetype" => array("id" => $this->issueType),
)
);
if (!empty($this->assignee)) $this->data['fields']['assignee'] = $this->assignee;
if (!empty($this->labels)) $this->data['fields']['labels'] = $this->labels;
foreach($this->customFields as $key => $val){
$this->data['fields'][$key] = $val;
}
$issue = $this->execCURL();
return $issue;
}
函数 execCURL() 获取 PHP 数组 ($this->data) 并使用 PHP cURL.[=12= 发送它]
希望以上内容对您有所帮助!