How to get Json Response from AMFPHP Library?

155 Views Asked by At

I have API, which returns application/x-amf reseponse. I want to convert it to application/json. Is there any way AMFPHP library supports this conversion?

I am using AMFPHP library version 1.6 .

1

There are 1 best solutions below

0
Marcus Frasier On

I am not sure about 1.6, but in the 2.x version, you can actually just post JSON data to your AMFPHP endpoint and have it return data.

For example

    $apiURL = 'https://www.yourapi.url/';
    $curl = curl_init();

    ## headers
    $headers = array(
        "Connection: Keep-Alive",
        "Content-Type: application/json"
    );
    curl_setopt( $curl, CURLOPT_HEADER, false );
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers);

    ## params
    $variables = ["serviceName"=> $THE_NAME_OF_THE_SERVICE, "methodName" => $THE_NAME_OF_THE_METHOD, "parameters" => [] ];
    curl_setopt( $curl, CURLOPT_POST, true );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, json_encode($variables) );


    ## submit
    curl_setopt( $curl, CURLOPT_URL, $apiURL );
    $data = curl_exec( $curl ) or error_log( "Error: " . curl_error($curl) );

Hope that helps