Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda