Link to home
Start Free TrialLog in
Avatar of Nico2011
Nico2011Flag for United Kingdom of Great Britain and Northern Ireland

asked on

JSON-RPC Feed - PHP/JavaScript

Hello,

I have two PHP files (attached) - file1.txt (should be PHP) works, the other, file2.txt (PHP) doesn't... the first one doesn't call any fields from the feed, the second does.

I download the data into a local file for processing - my file gets created in both instances, however the second file creates a file with only 1k size, whereas the file should be far larger.

I receive an OxFF message from Windows Scheduler when I run the PHP file.

HELP - please!

Thanks in advance.
file1.txt
file2.txt
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nico2011

ASKER

YES Julian - that's EXACTLY what I meant ;-)<br /><br />I'm new to PHP, so will do many silly things...<br /><br />Thanks very much - works a dream!
Just guessing, but might this be what you want?  If you have any documentation on how to use the web service it might give an example.

<?php // RAY_temp_nico2011.php
ini_set('max_execution_time', 300);
error_reporting(E_ALL);

/* THIS STATEMENT IS FALSE: Methodname is part of the URL */
/* The JSON method name is part of the URL. use only lowercase characters in the URL */

$url = "https://listofhousesv1.jsonrpc-partner.net/cgi/lars/jsonrpc-partner/jsonrpc.htm";

$post_data = array
( 'jsonrpc' => '2.0'
, 'method'  => 'ListOfHousesV1'
, 'params'  => array
  ( 'WebpartnerCode'     => 'XXXXXXXX',
    'WebpartnerPassword' => 'XXXXXXXX',
    'SelectionFields' => array
                        ( 'MaxNumberOfPersons'
                        , 'Country'
                        , 'HouseType'
                        )
, 'id'      => 461930148
)
;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/json'));  /** For large amounts of data use compression for better performance :curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/json','Accept-Encoding: gzip,deflate'));  **/
curl_setopt($ch, CURLOPT_SSLVERSION,3); /* Due to an OpenSSL issue */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  /* Due to a wildcard certificate */
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_ENCODING, 1); /* If result is gzip then unzip */
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if ($result = curl_exec($ch))
{
    if ($res = json_decode($result))
    {
        // WRITE THE RESPONSE TO DISK
        file_put_contents('c:\data\ListOfHouses.txt', $result);
        //print_r($res);
    }
    else echo json_last_error();
}
else
{
    echo curl_error($ch);
}

curl_close($ch);

Open in new window

I'm new to PHP, so will do many silly things...
I guarantee there is not an expert here who did not go through this stage.

Glad to help - keep at it.

Thanks for the points
Hi Ray,

Thanks for your answer too - I had first received Julian's response - yours must have come in as I was answering Julian's - your code from the other day worked perfectly - I just needed to add the array.

Thanks again and best wishes/Nico