Receive XML response using CURL

1

I have a code that returns a response from Amazon MarketPlace, it is by get and I get the answer by cURL, if I put the URL in the browser it brings me the xml, however if I do it by php it brings me the plain text, even I do not know much about CURL and I'd like to either bring the xml with the tags or bring the most ordered data, (currently it brings me all the fields followed - unintelligible).

So I have my code:

  $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"))
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

   $info = curl_getinfo($ch);
   curl_close($ch);

   echo('<p>' . $response. '</p>');
   print_r($info);
    ?>
    
asked by Andress Blend 30.10.2017 в 15:15
source

1 answer

1

You have two errors

1. You must send the content-type in the header:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")

2. You must enable the transfer of the answer:

curl_setopt($ch , CURLOPT_RETURNTRANSFER , true);

This library is very used you can have the documentation in the PHP manual

I also invite you to read more about the library cURL this site is in English but at the end of the account all languages of programming execute this instruction below

    
answered by 30.10.2017 / 15:35
source