@@ -67,11 +67,14 @@ class RpcClient
6767
6868 private string $ nodeUrl ;
6969
70+ private array $ headers ;
71+
7072 private ?string $ lastApiVersion = null ;
7173
72- public function __construct (string $ nodeUrl )
74+ public function __construct (string $ nodeUrl, array $ headers = array () )
7375 {
7476 $ this ->nodeUrl = $ nodeUrl ;
77+ $ this ->headers = $ headers ;
7578 }
7679
7780 public function getLastApiVersion (): ?string
@@ -461,20 +464,23 @@ private function rpcCallMethod(string $method, array $params = array()): array
461464 {
462465 $ url = $ this ->nodeUrl . '/rpc ' ;
463466 $ curl = curl_init ($ url );
464- $ data = array (
465- 'id ' => self ::ID ,
466- 'jsonrpc ' => self ::JSON_RPC ,
467- 'method ' => $ method ,
468- 'params ' => $ params
469- );
467+
468+ $ headers = ['Accept: application/json ' , 'Content-type: application/json ' ];
469+ foreach ($ this ->headers as $ name => $ value ) {
470+ $ headers [] = "$ name: $ value " ;
471+ }
470472
471473 curl_setopt ($ curl , CURLOPT_URL , $ url );
472474 curl_setopt ($ curl , CURLOPT_POST , true );
473475 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
474- curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode ($ data ));
475- curl_setopt ($ curl , CURLOPT_HTTPHEADER , array (
476- 'Accept: application/json ' ,
477- 'Content-type: application/json ' ,
476+ curl_setopt ($ curl , CURLOPT_HTTPHEADER , $ headers );
477+ curl_setopt ($ curl , CURLOPT_POSTFIELDS , json_encode (
478+ array (
479+ 'id ' => self ::ID ,
480+ 'jsonrpc ' => self ::JSON_RPC ,
481+ 'method ' => $ method ,
482+ 'params ' => $ params
483+ )
478484 ));
479485
480486 $ response = curl_exec ($ curl );
0 commit comments