2015-10-15 61 views
-1

我已经尝试过下面的代码进行登录验证,但它不工作。使用php登录

<?php 
define('URL', 'https://xxxxxxxxxxxx.com'); 
function authenticate($uname, $pass) { 

    $url = URL . 'Issue/Bug-5555'; 

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_USERPWD, "$uname:$pass"); 
    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; 
} ?> 
+0

什么不工作?你有错误信息吗? – Reeno

+0

是的,我只收到错误消息 – vijay

+0

欢迎使用堆栈溢出。我在你的文章中修复了一些英文问题。请解释什么不起作用。它是否给出错误,是否挂断? –

回答

-1

您在URL中缺少斜杠。该$url传递目前卷曲具有价值:

https://jira.hawkdefense.comIssue/Bug-5555 

curl_exec()线后,插入这和复制/结果贴在这里。

if (curl_errno($url)) { 
    throw new Exception(curl_error($url)); 
} 
0

你没有提到你用这段代码试图达到的目标。 您是否试图获取机票信息,发布问题?你只是使用API​​ ...

那么这里是一个脚本,与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); 
?> 

此代码正在从JIRA获取项目。 如果您想创建问题,您必须将REST URL更改为/ rest/api/2/issue /,并使用“POST”而不是“GET”方法。

+1

标记为重复然后,你不是真的提供一个答案 – ochi