<p>You can use the command-line curl or any of the various JSON-RPC examples listed <a href="https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29" rel="nofollow noreferrer">here</a>.</p>
<p>In particular, you can use curl like this:</p>
<pre><code>$ curl --user &lt;username&gt;:&lt;password&gt; --data-binary '{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;:&quot;curltest&quot;, &quot;method&quot;: &quot;getinfo&quot;, &quot;params&quot;: [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
</code></pre>
<p>For PHP, you can use <a href="https://github.com/soundasleep/jsonrpcclient" rel="nofollow noreferrer">this library</a> and do:</p>
<pre><code>require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');

echo &quot;&lt;pre&gt;\n&quot;;
print_r($bitcoin-&gt;getinfo()); echo &quot;\n&quot;;
echo &quot;Received: &quot;.$bitcoin-&gt;getreceivedbylabel(&quot;Your Address&quot;).&quot;\n&quot;;
echo &quot;&lt;/pre&gt;&quot;;
</code></pre>

CC BY-SA 4.0
2015-11-13T22:53:49.177Z
2020-09-21T12:13:15.257Z
2020-09-21T12:13:15.257Z
Jimmy Song
<p>I am wondering if its possible to use curl to getinfo from the bitcoin server thanks.  </p>

<pre><code>&lt;?php
// init the resource
$ch = curl_init();

// set a single option...
$username = 'usernamefromconfig';
$pwd = 'passwordfromconfig';

curl_setopt_array(
    $ch, array( 
    CURLOPT_URL =&gt; "$username:$pwd@127.0.0.1:8336",
    CURLOPT_RETURNTRANSFER =&gt; true
));

$output = curl_exec($ch);
echo $output;

// free
curl_close($ch);
?&gt;
</code></pre>

<api><json-rpc><php>
Can I use curl to call getInfo from a the Bitcoin server?
Levon Willson
# Can I use curl to call getInfo from a the Bitcoin server?

(Asked by: username_0 on 2015-11-13)

I am wondering if its possible to use curl to getinfo from the bitcoin server thanks.  
 "$username:$pwd@127.0.0.1:8336",
    CURLOPT_RETURNTRANSFER => true
));

$output = curl_exec($ch);
echo $output;

// free
curl_close($ch);
?>

**Tags:** api, json-rpc, php


---

## 1 answers

### Answer by username_1 on 2015-11-13. Score: 4 | Accepted answer

You can use the command-line curl or any of the various JSON-RPC examples listed here.
In particular, you can use curl like this:
$ curl --user : --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

For PHP, you can use this library and do:
require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');

echo "\n";
print_r($bitcoin->getinfo()); echo "\n";
echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";
echo "";


---

