When I execute my php file from the command line I get this:
<pre>
PHP Warning: fopen(http://[email protected]:8332/): failed to open stream: HTTP request failed! HTTP/1.0 401 Authorization Required
in /home/brian/Desktop/VH2_apache2/host02/btc16/jsonRPCClient.php on line 132
PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://b:[email protected]:8332/' in /home/brian/Desktop/VH2_apache2/host02/btc16/jsonRPCClient.php:140
Stack trace:
#0 /home/brian/Desktop/VH2_apache2/host02/btc16/index1.php(12): jsonRPCClient->__call('getinfo', Array)
#1 /home/brian/Desktop/VH2_apache2/host02/btc16/index1.php(12): jsonRPCClient->getinfo()
#2 {main}
thrown in /home/brian/Desktop/VH2_apache2/host02/btc16/jsonRPCClient.php on line 140
My php file looks like this:
<?php
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://user:[email protected]:8332/',true);
#$param = array(
#'c418518d5ffccd947e377ab7e589f684d83e6df1af8f397cc11848ac8a78f0dd',
#'1');
#$return1 = $bitcoin->getrawtransaction('c418518d5ffccd947e377ab7e589f684d83e6df1af8f397cc11848ac8a78f0dd','1')
echo "<pre>\n";
print_r($bitcoin->getinfo()); echo "\n";
#print_r($return1['0']); echo "\n";
#echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";
echo "</pre>";
?>
My webpage with apache2 appears blank that uses the php file I made. I am using the -txindex parameter when I launch bitcoind.
But I am able to use bitcoin-cli to interact with bitcoind
Iv'e used:
bitcoin-cli getrawtransaction c418518d5ffccd947e377ab7e589f684d83e6df1af8f397cc11848ac8a78f0dd 1
and:
bitcoin-cli getinfo
Also my bitcoin.conf looks like this:
rpcuser=user
rpcpassword=pass
txindex=1
server=1
Also note that I substituted the usernames and passwords to hide them.
My question is why can I use bitcoin-cli and get no error, but when I try to use the jsonRPCClient.php I get the error 401 Authorization Required and how do I fix the error?
pass
in your config file, and it'spassword
in your config file. Does that reflect the contents of your config/php files?