3
When I execute my php file from the command line I get this:
<pre>
PHP Warning: fopen(http://...@127.0.0.1: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:a@127.0.0.1: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:password@127.0.0.1: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?
Error 401 means bad user/password. I notice that the password is
passin your config file, and it'spasswordin your config file. Does that reflect the contents of your config/php files? – Nick ODell – 2015-04-17T18:28:36.787No, sorry for the confusion, I replaced my password and username listed on this forum to maintain security of the bitcoin core on my computer. The password and username I used on my computer match with those in the config file and I have checked many times. – Gemohn Herbile – 2015-04-17T23:48:53.523
I dunno what to tell you. Bad user/pass is what triggers the error.
– Nick ODell – 2015-04-17T23:59:05.597Have you restarted your client since putting the username and password in the conf file? – morsecoder – 2015-04-18T13:12:42.213
I think so, I have re-started my php script and bitcoind as well, and the wierd thing is that it worked at one point. – Gemohn Herbile – 2015-04-18T13:26:04.633
I've now discovered its partially caused by leaving armory bitcoin wallet manager open for days. – Gemohn Herbile – 2015-07-05T06:43:17.867