这是我的PHP代码,用于在本地主机上打印Cardano币节点信息:
<?php
class Cardano {
private $host;
private $port;
private $disableSSLVerification;
public $httpCode;
// The option to not use an SSL certificate doesn't work anymore, so you need to tell curl where to find the certificate.
const pem = '/home/softmac/Documents/cardano-sl/state-wallet-mainnet/tls/client/client.pem';
public function getInfo()
$infos = json_encode($this->get('/api/v1/node-info') , true);
print_r($infos);
private static function jsonDecode(string $content):
array
$data = json_decode($content, true);
if (!is_array($data)) throw new Exception($content);
else
//print_r($data['data']); //----it will print array/value of any data
return $data;
// CURL Get
public function get(string $endPoint):
string
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $this->host . ':' . $this->port . $endPoint);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSLCERT, Cardano::pem);
//curl_setopt($ch, CURLOPT_SSLVERSION, 2);
if ($this->disableSSLVerification)
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
$this->httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_exec($ch) === false)
throw new Exception('Curl error: ' . curl_error($ch));
curl_close($ch);
return $data;
$client = new Cardano('https://127.0.0.1', 8090, true);
print_r($client->getInfo());
?>
此代码使用php hello.php在命令行上成功运行。当我的系统上有apache2时,它在localhost(浏览器)上不打印任何内容。在终端上运行时,它可以成功创建钱包,但是在浏览器中,它会像https://localhost:8090/api/v1/wallets