1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XML response REST CURL - Help

Discussion in 'PHP & Perl' started by Painkiller009, Oct 7, 2010.

  1. Hi,

    I have used the following script to consume REST webservices provided by Commission Junction. I'm able to get the response but the response is not in xml format.
    PHP:
    <?php

    $targeturl
    ="xxxxxxxxxx";
     
    $CJ_DevKey"xxxxxxxxx";

    // return xml feed from CJ

    $ch curl_init($targeturl);
    curl_setopt($chCURLOPT_POSTFAlSE);
    curl_setopt($chCURLOPT_HTTPHEADER, array('Authorization: '.$CJ_DevKey));
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    $response curl_exec($ch);
    curl_close($ch);

    echo 
    $response// will print in browser all country codes in an xml format

    /*

    ADD YOUR OWN CODE HERE TO DO WHAT YOU WANT WITH THE RESPONSE.  MAYBE SAVE RESULTS TO A FILE OR THE PARSE THE RESULTS INTO A DATABASE?

    */

    ?>
    I'm just confused. Isn't that the response when using REST webservices is always in xml format. Please correct me if I'm wrong.

    Would someone please have a look at this script and suggest me what I need to do in order to get the response in xml ? I want to save the response in xml file and then process it later.

    What I did is just saved the code into php file and opened it using my browser and the output is all text. Am I doing something wrong ?
     
  2. cashfap

    cashfap Junior Member

    Joined:
    May 5, 2010
    Messages:
    115
    Likes Received:
    14
    Location:
    Estonia
    try html_entity_decode

    PHP:

    $convert 
    html_entity_decod($response);
    echo 
    convert