Jump to content

Webservice Response in XML


WWW_9hub_Net

Recommended Posts

Hello,

 

I'm trying to get webservice response in xml format. I'm getting the response but it's not in xml. It's just text.

 

Can someone please look at the code ?

 

<?php

$targeturl="https://api.com";

$DevKey= "xxxxx";

// return xml feed

$ch = curl_init($targeturl);
curl_setopt($ch, CURLOPT_POST, FAlSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$DevKey));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
$xml = new SimpleXMLElement($response);
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?

*/

?> 

Link to comment
https://forums.phpfreaks.com/topic/214415-webservice-response-in-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.