diff --git a/classes/Endpoint.php b/classes/Endpoint.php
index baf5906baaf304aa5e9b32a69c705fab2690a649..a7db5bfd3e14eb636804d69416ed886958388b8f 100644
--- a/classes/Endpoint.php
+++ b/classes/Endpoint.php
@@ -9,27 +9,38 @@ class Endpoint{
   	$this->params = $params;
   }
   
-  public function query($q, $output = 'json'){
-  	global $conf;
-  	$auxoutput = $this->params['output'];
-  	if($output != null){
-  	  $this->params['output'] = $output;
-    }
-  	$context = stream_context_create(array(
-  	  'http' => array('header'=>'Connection: close')));
-  	$params = $this->params;
-  	$params['query'] = $q;
-  	$url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
-  	$aux = file_get_contents($url, false,$context);
-  	
-  	$this->params['output'] = $auxoutput;
-  	
-  	if(preg_match("/select/i", $q)){
-  	  return json_decode($aux, true);
-  	}
-  	if(preg_match("/describe/i", $q)){
-  	  return $aux;
-  	}  	
+   public function query($q, $output = 'json'){
+        global $conf;
+        $auxoutput = $this->params['output'];
+        $accept = 'application/sparql-results+json';
+        if($output != null){
+          $this->params['output'] = $output;
+        }
+
+        if($output == 'xml'){
+          $accept = 'application/sparql-results+xml';
+        }
+        $c = curl_init();
+        $context = array();
+        $context[0] = 'Connection: close';
+        $context[1] = 'Accept: '.$accept;
+        $params = $this->params;
+        $params['query'] = $q;
+        $url = $this->sparqlUrl.'?'.http_build_query($params, '', '&');
+
+        curl_setopt($c, CURLOPT_URL, $url);
+        curl_setopt($c, CURLOPT_HTTPHEADER, $context);
+        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+        $aux = curl_exec($c); // execute the curl command 
+        curl_close($c);
+        $this->params['output'] = $auxoutput;
+
+        if(preg_match("/select/i", $q)){
+          return json_decode($aux, true);
+        }
+        if(preg_match("/describe/i", $q)){
+          return $aux;
+        }
   }
   
   public function queryPost($q){