Consuming RestFull Services with Joomla

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
dskonig
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Jan 09, 2018 10:35 pm

Consuming RestFull Services with Joomla

Post by dskonig » Tue Jan 09, 2018 10:45 pm

I am consuming a web service, which I do with cUrl, the size of the content is correct, but the information appears badly formatted in the var_dump with ASCII characters, this is the code I use to consume the service.

Code: Select all

    $url = "http://mywebservices.ddns.net:49156/PrdEXObt?ID=fb8e8d73-cf98-461c-94c0-3c5cbfd02b86&Prd=1034-12V&Fmt=XML&Enc=8";
    $headers = [
        'Accept-Encoding: gzip'             
    ];

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $curl_response = curl_exec($ch);
    curl_close($ch);        
    var_dump($curl_response);
This is how the information appears

Image


When I consume the web service from a RESTful client, the information appears correctly, example:


Image

What is missing or what error do I have in my code? What is a viable solution?

Thanks
Last edited by toivo on Wed Jan 10, 2018 12:55 am, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30935
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Consuming RestFull Services with Joomla

Post by Per Yngve Berg » Wed Jan 10, 2018 9:55 pm

I presume you have to unzip the compressed information first as gzip was requested.

dskonig
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue Jan 09, 2018 10:35 pm

Re: Consuming RestFull Services with Joomla

Post by dskonig » Wed Jan 10, 2018 11:22 pm

Per Yngve Berg wrote:I presume you have to unzip the compressed information first as gzip was requested.
thanks for the help, unzipping was what was missing

Code: Select all

		
$data = gzinflate(substr($curl_response,10,-8));
$data_decode = json_decode($data);		


Locked

Return to “Joomla! 3.x Coding”