使用REST API身份验证错误通过PHP连接到VCenter [英] Connecting to VCenter with PHP using REST API authentication error
问题描述
我按照vSphere官方网站上的说明从服务器和此处的另一个用户的答复中获取信息. . 据我了解,首先我必须获取会话ID(顺式ID),但结果是空".
I followed the instructions in the official vsphere site to get info from the server and from the answer of another user here . From what I have understood, firstly I have to get the session id (cis id), but I got "null" as a result.
我尝试了多个代码,但结果是相同的:
I tried multiple codes but the result is the same:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array(
'Content-Type: application/json',
'Accept: application/json',
'vmware-use-header-authn: test'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://vcsa/rest/com/vmware/cis/session");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'administrator@vs.dom:userpassword');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
$out = json_decode(curl_exec($ch));
// var_dump($out);
if ($out === false) {
echo 'Curl Error: ' . curl_error($ch);
exit;
}
$sid = $out;
dd($out);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("vmware-api-session-id:$sid"));
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, "https://vcsa/rest/vcenter/vm");
$output = curl_exec($ch);
$vms = json_decode($output);
var_dump($vms);
curl_close($ch);
结果为空.
推荐答案
在调试代码时,$ out变量返回null吗?
如果是,是否可以检查curl是否在$out = json_decode(curl_exec($ch));
中返回 56-OpenSSL SSL_read:成功错误?
when you debug your code, the $out variable return null?
If yes, can you check if your curl returns 56 - OpenSSL SSL_read: Success error in $out = json_decode(curl_exec($ch));
?
此错误出现在我的代码中,并且我看到7.67版本中的cURL引起了此麻烦.
This error occoured with my code, and I see wich cURL in 7.67 version cause this trouble.
我的解决方案是将cURL版本降级到7.65.
My solution was to downgrade cURL version to 7.65.
对我有用!
这篇关于使用REST API身份验证错误通过PHP连接到VCenter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!