我正在使用JIRA API但是当我调用curl得到401错误时。请告诉我我的错误。
回复是:
Unauthorized (401)
Encountered a "401 - Unauthorized" error while loading this page.
我的代码如下:
$username = '********@gmail.com';
$password = '********';
$url = 'https://vikasxtreem.atlassian.net/rest/api/2/issue/JRA-9';
$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);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$issue_list = (curl_exec($curl));
echo $issue_list;
答案 0 :(得分:0)
添加
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
到选项列表。
同时检查您是否正在通过需要身份验证的代理。