Jump to content



  • Please log in to reply
No replies to this topic

#1 blunt

  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationCape Town, S.Africa

Posted 24 August 2006 - 09:25 AM

Hello, I am having a problem using CURL to query a JSON-RPC server, If I do the following using CURL via commandline:

-bash-2.05b$ curl --data-binary '{"method": "push", "value": "hello"}' -H 'content-type: text/plain;'
-bash-2.05b$ curl --data-binary '{"method": "pop"}' -H 'content-type: text/plain;'

This executes successfully as you can see, now I have the following PHP Code:
// setup json data
$url = "";
$post_data = array('method' => 'push', 'value' => 'testing');
$post_data = json_encode($post_data);
echo $post_data.'<br/>';
// execute json request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 'content-type: text/plain;');
curl_setopt($ch, CURLOPT_TRANSFERTEXT, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// decode result
if ($result = @curl_exec($ch)) {
	echo 'query success<br/><pre>';
	echo '</pre>';
} else {
	'query failed';
Script outputs the following:

query success

stdClass Object
    [response] => stdClass Object
            [error] => Unkown method, list of known methods: ['push', 'pop']


Is there anything here I am doing wrong, I have set it to post the data using plaintext in the correct json format... something I'm missing here?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users