cURL returns 找不到项目错误

cURL returns No project could be found error

我正在尝试使用 php 通过 jira REST API 获取结果,但我得到了意想不到的结果。当我直接在浏览器上输入 URL: http://localhost:8080/rest/api/2/project/ABCD/components 时,我得到了一个结果(有效),但是当我通过 php 执行时,我得到以下错误:

string(76) "{"errorMessages":["No project could be found with key 'RELM'."],"errors":{}}"

以下是php代码:

    $key = trim('RELM');
$ch = curl_init();
$url = "http://localhost:8080/rest/api/2/project/$key/components";
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//  curl_setopt($ch,CURLOPT_HEADER, false);

$output=curl_exec($ch);

curl_close($ch);
var_dump($output) ;

当您从浏览器尝试 url 时,您可能首先登录了 JIRA,但您的 php 代码中没有任何身份验证。

您需要经过身份验证才能获得正确的结果。例如。您可以将基本身份验证与有权浏览(或管理,具体取决于您想要做什么)该项目的 JIRA 用户的凭据一起使用。

另见 this question