Bitcoin Forum

Bitcoin => Project Development => Topic started by: carlosdelagarza on January 28, 2017, 05:54:46 AM



Title: JSON RPC API call from webpage
Post by: carlosdelagarza on January 28, 2017, 05:54:46 AM
Hello, I want to make API calls to my Bitcoin Core wallet from my webpage but when I try to connect it gives me Internal Server Error

I'm using easybitcoin.php JSON from https://github.com/aceat64/EasyBitcoin-PHP (https://github.com/aceat64/EasyBitcoin-PHP)

I'm trying with this JSON RPC call:

Code:
<?php
require_once(
'easybitcoin.php');
        
$bitcoin = new Bitcoin('myusername','mypassword','myip','8332');
        
$bitcoin->getinfo();
?>


My bitcoin.conf file has:

Code:
listen=1
maxconnections=15
server=1
daemon=1
rpcuser=myusername
rpcpassword=mypassword
rpcclienttimeout=60
rpcport=8332
rpcallowip=0.0.0.0/0 (Before I put my IP address here but it didn't solve too)

When I use bitcoin-cli.exe client to send commands to my Bitcoin Core server via 127.0.0.1 (localhost) it works perfectly.

What I'm doing wrong?


Title: Re: JSON RPC API call from webpage
Post by: fikihafana on January 28, 2017, 02:51:02 PM
have you unblock ip or port address?


Title: Re: JSON RPC API call from webpage
Post by: RHavar on January 28, 2017, 10:50:00 PM
You need to log the actual error, probably a setting in PHP so you see what the 'internal error' is, not just that one exists. From there it'll make it a lot easier to find what's going wrong.


Title: Re: JSON RPC API call from webpage
Post by: carlosdelagarza on January 29, 2017, 06:09:23 AM
have you unblock ip or port address?

I have opened my port.

I tested it on http://www.whatsmyip.org/port-scanner/

https://i.imgur.com/XRocWqL.jpg


Title: Re: JSON RPC API call from webpage
Post by: carlosdelagarza on January 29, 2017, 06:51:58 AM
You need to log the actual error, probably a setting in PHP so you see what the 'internal error' is, not just that one exists. From there it'll make it a lot easier to find what's going wrong.

The error says

Quote
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.


Title: Re: JSON RPC API call from webpage
Post by: cloverme on January 30, 2017, 02:32:13 PM
Look in your httpd error log file, you should find more information there.

SELinux may be preventing access as well (to port or local files), you may want to check the logs.
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Which_Log_File_is_Used.html


Title: Re: JSON RPC API call from webpage
Post by: nemgun on January 30, 2017, 03:50:11 PM
change rpcallowip = localhost or 127.0.0.1
you could also add more info to your querry, like the protocol, which is generally http :

Code:
<?php
require_once(
'easybitcoin.php');
        
$bitcoin = new Bitcoin('myusername','mypassword','myip','8332''http');
        
$bitcoin->getinfo();
        
// You can do a small test here
        
$test $bitcoin->getinfo();
        echo 
$test;

?>


.conf :

Code:
listen=1
maxconnections=15
server=1
daemon=1
rpcuser=myusername
rpcpassword=mypassword
rpcclienttimeout=60
rpcport=8332
rpcallowip=localhost or 127.0.0.1 (unless you want to query it from a remote computer, if so, just enter the ip address)