我在Ubuntu服务器上设置了一个比特币守护进程 这是我的bitcoin.conf
rpcuser=usernamebitcoin
rpcpassword=mypasswordbitcoin
rpcallowip=127.0.0.1
rpcallowip=xxx.xxx.xxx.xxx
rpcallowip=xxx.xxx.xxx.xxx
rpcport=8332
server=1
daemon=1
listen=1
txindex=1
我试图将Curl从php发送到我的比特币守护程序。 当我在终端中使用此命令行时,它可以工作
curl --user usernamebitcoin --data-binary '{"jsonrpc": "1", "id":"", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain' http://xxx.xxx.xxx.xxx:8332/
但是当我从php尝试它时它会给我500错误。
这是我的PHP代码:
<?php
$postfields = [
'jsonrpc' => '1',
'id' => '',
'method' => 'getbalance',
'params' => [],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://xxx.xxx.xxx.xxx:8332/" );
curl_setopt($ch, CURLOPT_USERPWD, "usernamebitcoin:mypasswordbitcoin");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
$output = curl_exec($ch);
$info = curl_getinfo($ch);
echo "<pre>";
print_r($info);
curl_close($ch);
?>
这是来自服务器的回复
Array
(
[url] => http://xxx.xxx.xxx.xxx:8332/
[content_type] => application/json
[http_code] => 500
[header_size] => 152
[request_size] => 235
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.106437
[namelookup_time] => 3.6E-5
[connect_time] => 0.035309
[pretransfer_time] => 0.035477
[size_upload] => 528
[size_download] => 74
[speed_download] => 695
[speed_upload] => 4960
[download_content_length] => 74
[upload_content_length] => 528
[starttransfer_time] => 0.070569
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => xxx.xxx.xxx.xxx
[certinfo] => Array
(
)
[primary_port] => 8332
[local_ip] => xxx.xx.xxx.xxx
[local_port] => 41040
)