php - CURL returns full string response instead of xml -


i'm trying pull data using curl in php this

$ch = curl_init(); $headers = array('content-type: text/xml',"openapikey:da21d9s56ekr33"); curl_setopt($ch, curlopt_url, "http://api.test.co.un/rest/cateservice/category"); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_failonerror,1); curl_setopt($ch, curlopt_followlocation,1); curl_setopt($ch, curlopt_returntransfer,1); curl_setopt($ch, curlopt_timeout, 15);  $return = curl_exec($ch); print_r($return); print_r(gettype($return)); //prints string 

but got response in full string when response supposed in xml format, , when print type of response variable prints string. tried using postman check response , returns correct format in xml mode:

xml format

and when change preview mode in postman, showed same result curl response in php shows, full string:

string format

most likely, you're getting correct response, browser not rendering way expected to. happens if, @ top of code, add header("content-type: text/plain;charset=utf8"); ? guess, render code way expected to. alternatively, html encode it, like

function hhb_tohtml(string $str):string {     return htmlentities($str, ent_quotes | ent_html401 | ent_substitute | ent_disallowed, 'utf-8', true); } print_r(hhb_tohtml($return)); print_r(gettype($return)); //prints string 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -