卷曲登录身份验证 [英] Login authentication with curl
问题描述
我想用JIRA API,卷曲操作登录。
我具有卷曲的操作问题。我在JIRA_URL主URL'/演示/ 111。为$ username和$ password值在正常工作通过,但显示状态为失败。是否有任何问题,在我的卷曲code
函数JIRA_authenticate($的用户名,密码$){ $ URL = JIRA_URL。 '/演示/ 111';
$卷曲= curl_init();
curl_setopt($卷曲,CURLOPT_USERPWD,$用户名:密码$);
curl_setopt($卷曲,CURLOPT_URL,$网址); curl_setopt($卷曲,CURLOPT_RETURNTRANSFER,1);
curl_setopt($卷曲,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($卷曲,CURLOPT_SSL_VERIFYPEER,0); // SSL证书保证
curl_setopt($卷曲,CURLOPT_SSL_VERIFYHOST,1); /// SSL证书保证 $ issue_list =(curl_exec($卷曲));
回声$ issue_list; 返回$ issue_list;
}
您没有提到你试图实现这个code什么。
你们是不是要买到票的信息,发布一个问题?你只是使用API ...
那么这里的,与JIRA API工作的脚本。
< PHP
$用户名=测试;
$密码=测试;
$ URL =https://xxxxx.xxxxxxx.net/rest/api/2/project;$ CH = curl_init();$头=阵列(
接受:应用/ JSON,
内容类型:应用程序/ JSON
);
$测试=这是自定义字段的内容。
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);
curl_setopt($ CH,CURLOPT_VERBOSE,1);
curl_setopt($ CH,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ CH,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ CH,CURLOPT_HTTPHEADER,$头);
curl_setopt($ CH,CURLOPT_CUSTOMREQUEST,GET);// curl_setopt($ CH,CURLOPT_POSTFIELDS,$数据);
curl_setopt($ CH,CURLOPT_URL,$网址);curl_setopt($ CH,CURLOPT_USERPWD,$用户名:密码$);
$结果= curl_exec($ CH);
$ CH_ERROR = curl_error($ CH);如果($ CH_ERROR){
回声卷曲错误:$ CH_ERROR
}其他{
回声$结果;
}curl_close($ CH);
?>
这code为获取从JIRA的一个项目。
如果你想创建问题,您必须将REST URL更改为/ REST / API / 2 /问题/并使用POST,而不是GET方法。
I want to login using JIRA API with curl operation.
I having problem in curl operation. I have main URL in JIRA_URL.'/demo/111'; values for $username and $password are passed in the function correctly but shows the status 'failure'. Is any issues in my curl code
function JIRA_authenticate($username, $password) {
$url = JIRA_URL . '/demo/111';
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // ssl ensure cert
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); /// ssl ensure cert
$issue_list = (curl_exec($curl));
echo $issue_list;
return $issue_list;
}
You didn't mention what you are trying to achieve with this code. Are you trying to get a ticket info, post an issue? You are just using the API...
Well here's a script that works with the JIRA API.
<?php
$username = 'test';
$password = 'test';
$url = "https://xxxxx.xxxxxxx.net/rest/api/2/project";
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);
$test = "This is the content of the custom field.";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
curl_close($ch);
?>
This code is fetching a project from JIRA. If you want to create issues, you will have to change the REST URL to /rest/api/2/issue/ and use "POST" instead of "GET" method.
这篇关于卷曲登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!