JSON RPC from external server


I'm having trouble connecting to my node via JSON RPC from an external server. On the same machine, I'm able to pass the commands through bitcoin-cli and also locally I am able to run this PHP file which passes successfully. Once I try to do the same from an external source, I receive an error. I've allowed my webservers IP, under the conf file as rpcallowip. I know it's default it to only accept local requests, but I thought as long as I enter in the rpcallowip then I would be able to do the same from another server. I've even tried to add a range on my IPs allowed, no luck.

My Conf:



require_once 'jsonRPCClient.php';

$btc= new jsonRPCClient('http://userRPC:passRPC@');

echo "<pre>\n";
echo "</pre>";

The above works perfectly when running locally. I'll change the above IP address to my node and then try to run it on an external server and I get a blank response as if my node isn't even running.

Error response received when running from external server:

Fatal error:  Uncaught exception 'Exception' with message 'Incorrect response id (request id: 1, response id: )' in /home/coincxby/public_html/jsonRPCClient.php:152
Stack trace:
#0 /home/coincxby/public_html/node.php(8): jsonRPCClient->__call('getinfo', Array)
#1 /home/coincxby/public_html/node.php(8): jsonRPCClient->getinfo()
#2 {main}
  thrown in /home/coincxby/public_html/jsonRPCClient.php on line 152

Successful response when I run locally:

    [version] => 110100
    [protocolversion] => 70002
    [walletversion] => 60000
    [balance] => 0
    [blocks] => 390322
    [timeoffset] => 3
    [connections] => 11
    [proxy] => 
    [difficulty] => 93448670796.324
    [testnet] => 
    [keypoololdest] => 1419183361
    [keypoolsize] => 104
    [paytxfee] => 1.0E-5
    [relayfee] => 5.0E-5
    [errors] => Warning: This version is obsolete; upgrade required!

The only difference between the two is I change the target IP in the PHP file, and I'm running from an external server. Any ideas why I can't hit my locally running node from an external server?


Posted 2015-12-26T18:01:46.530

Reputation: 4 083

Is your external server have curl available? May be able to get more information on the error. Error seems odd, like it's connecting but response is invalid.

curl --user userRPC --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;'
 – Dustin Butler  – 2015-12-26T21:10:41.627

Yea my external server has curl, but I'm confused. I'm using PHP so I'm used to initiating curl, setting the headers and curlopts then executing the curl request... not sure how I would execute the above request you suggested?@DustinButler – m1xolyd1an – 2015-12-26T21:18:58.270

That is curl command line. Would need to have console access (ssh or remote console) to run it. I think you want to see what the actual response is from your node. Maybe look at jsonRPCClient.php on line 152 where it's throwing the exception, and see if you can output the real response. May have a clue in it – Dustin Butler – 2015-12-26T21:35:16.667

Looking at the code for rcpclient try turning debug on $btc= new jsonRPCClient('http://userRPC:passRPC@', $debug=true);

– Dustin Butler – 2015-12-26T21:41:20.450

Ok, tried the above, same exact error as in the original post. @DustinButler – m1xolyd1an – 2015-12-26T21:52:09.240

No answers