Search code examples
phprestweb-servicesjoomla

Consuming RestFull Services with Joomla


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.

    $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

enter image description here

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

enter image description here

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


Solution

  • I needed to decompress the data, solved the problem

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