curl Atlassian Confluence基本登录API不工作:未找到页面

pepwfjgg  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(205)

在PHP中使用Atlassian Confluence基本登录API

$url = 'https://mysubdomain.atlassian.net/jira/rest/auth/1/session/';

    $curl = curl_init();
    $headers = array(
        'Content-Type:application/json',
        'Authorization: Basic '. base64_encode($username . ":" . $password)
    );
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);       
    //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_BINARYTRANSFER, 1);          
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);      
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    $postfields = array(
        'username' => urlencode($username),
        'password' => urlencode($password)
    );

    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode( $postfields ));
    $result = curl_exec($curl);

当我给予错误的用户名或密码时,它显示身份验证错误。
通过REST API进行Atlassian Confluence基本登录的正确代码是什么?

8iwquhpp

8iwquhpp1#

请尝试使用CURLOPT_USERPWD而不是Authorization标头。

curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

相关问题