在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基本登录的正确代码是什么?
1条答案
按热度按时间8iwquhpp1#
请尝试使用CURLOPT_USERPWD而不是Authorization标头。