Bitcoin Forum
May 12, 2024, 11:53:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PHP JSON-RPC connection problems while sending BTC [SOLUTION]  (Read 1688 times)
jokz (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
July 14, 2011, 02:55:28 PM
 #1

Hi, I'm russian PHP developer, now working with Bitcoin local server.

On the official wiki (https://en.bitcoin.it/wiki/PHP_developer_intro), connection with bitcoind server realised through JSON-RPC class for PHP.

It works, it can connect to the server and get info, balance etc. But if some error happens on the server side or any message should be forced in answer JSON-RPC class died.

The reason is: "Couldn't connect to server". It is very strange, that in first line of code you succefully getting info, but in the second line you couldn't connect while trying to send bitcoins to address.

I found the same problem discussing on this forum(http://forum.bitcoin.org/index.php?topic=28537.msg358974#msg358974) and other forums, but no solution was reached.

But the solution of this problem is easy. JSON-RPC class uses function fopen to connect to the server. That's bad, because in case of server want to send some information instead of good status, it sends it with status header 500 [Internal Server Error] and function fopen dies.

Code:
Post data: {"method":"sendtoaddress","params":["************ejLDXo65y98XfS3aj4MauH8",1.00000000,"dsfa","ghfhfg"],"id":1}

Answer:
HTTP/1.1 500 Internal Server Error
Date: Thu, 14 Jul 2011 14:31:34 +0000
Connection: close
Content-Length: 196
Content-Type: application/json
Server: bitcoin-json-rpc/0.3.23-beta

{"result":null,"error":{"code":-4,"message":"Error: This transaction requires a transaction fee of at least 0.0005 because of its amount, complexity, or use of recently received funds  "},"id":1}

Function fopen can't parse this result and returns an error. Everything you need is to use cURL or Socket functions instead of fopen. Here i found a script that just like JSON-RPC but works through cURL (http://forum.bitcoin.org/index.php?topic=9304.0)


I will be very glad if this information will help someone.

Question to moderators: what should i do to become an "establish" user ?Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!