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:
and when change preview mode in postman, showed same result curl response in php shows, full string:
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
Post a Comment