jsonRPCClient.php states its served a 401 error response When I execute my php file from the command line I get this:

&lt;pre&gt;
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-&gt;__call('getinfo', Array)
#1 /home/brian/Desktop/VH2_apache2/host02/btc16/index1.php(12): jsonRPCClient-&gt;getinfo()
#2 {main}
  thrown in /home/brian/Desktop/VH2_apache2/host02/btc16/jsonRPCClient.php on line 140




My php file looks like this:

&lt;?php
  require_once 'jsonRPCClient.php';

  $bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/',true);
  #$param = array(
  #'c418518d5ffccd947e377ab7e589f684d83e6df1af8f397cc11848ac8a78f0dd',
  #'1');

  #$return1 = $bitcoin-&gt;getrawtransaction('c418518d5ffccd947e377ab7e589f684d83e6df1af8f397cc11848ac8a78f0dd','1')

  echo "&lt;pre&gt;\n";
  print_r($bitcoin-&gt;getinfo()); echo "\n";
  #print_r($return1['0']); echo "\n";
  #echo "Received: ".$bitcoin-&gt;getreceivedbylabel("Your Address")."\n";
  echo "&lt;/pre&gt;";
?&gt;




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?
I think this is related to this open issue. 

https://github.com/bitcoin/bitcoin/issues/9661

I was running bitcoind on Ubuntu 16.

I had the similar issue when I had rpcuser and rpcpassword in the config file. All I got is 401 error when I called the jaon-rpc api.

I found a workaround by providing -rpcuser=REPLACED -rpcpassword=REPLACED when I launched the bitcoind.

Hope this is useful.

One more thing, instead of debug from your rpc client in PHP. Maybe try it with curl first. HTTP 401 clearly is an authentication issue, using curl is much easier for debugging.