Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
CURL returns full string response instead of xml

I'm trying to pull data using CURL in PHP like 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 i got the response in full string when the response supposed to be in xml format, and when i print the type of the response variable it prints string. I tried using Postman to check the response and it returns the correct format in XML mode:

xml format

and when i change to Preview mode in Postman, it showed the same result as what my CURL response in php shows, which is full string:

string format

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

most likely, you're getting the correct response, its just your browser not rendering it the way you expected it to. what happens if, at the top of your code, you add header("content-type: text/plain;charset=utf8"); ? my guess, it will render the code the way you expected it 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
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!