Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:01:06+00:00 2026-05-25T14:01:06+00:00

I have the following php code (getRout.php).. which response results in xml formats …

  • 0

I have the following php code (getRout.php).. which response results in xml formats … But I got this error :

XML Parsing Error: no element found
Location: http://127.0.0.1/direction2/getRout.php
Line Number 1, Column 1:

edit

You can see the xml response directly by requesting this url :

http://www.yournavigation.org/api/1.0/gosmore.php?format=kml&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik

getRout.php

<? require_once"RESTclient.class.php";
$url="http://www.yournavigation.org/api/1.0/gosmore.php?format=kml&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik";
$result=RestClient::get($url,$inputs); 
header("Content-type:text/xml");
echo($result->getResponse());?>

RESTclient.class.php

<? 

/** 
 * Class RestClient 
 * Wraps HTTP calls using cURL, aimed for accessing and testing RESTful webservice.  
 * By Diogo Souza da Silva <manifesto@manifesto.blog.br> 
 */ 
class RestClient { 

     private $curl ; 
     private $url ; 
     private $response =""; 
     private $headers = array(); 

     private $method="GET"; 
     private $params=null; 
     private $contentType = null; 
     private $file =null; 

     /** 
      * Private Constructor, sets default options 
      */ 
     private function __construct() { 
         $this->curl = curl_init(); 
         curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true); 
         curl_setopt($this->curl,CURLOPT_AUTOREFERER,true); // This make sure will follow redirects 
         curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); // This too 
         curl_setopt($this->curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers 
     } 

     /** 
      * Execute the call to the webservice 
      * @return RestClient 
      */  
     public function execute() { 
         if($this->method === "POST") { 
             curl_setopt($this->curl,CURLOPT_POST,true); 
             curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->params); 
         } else if($this->method == "GET"){ 
             curl_setopt($this->curl,CURLOPT_HTTPGET,true); 
             $this->treatURL(); 
         } else if($this->method === "PUT") { 
             curl_setopt($this->curl,CURLOPT_PUT,true); 
             $this->treatURL(); 
             $this->file = tmpFile(); 
             fwrite($this->file,$this->params); 
             fseek($this->file,0); 
             curl_setopt($this->curl,CURLOPT_INFILE,$this->file); 
             curl_setopt($this->curl,CURLOPT_INFILESIZE,strlen($this->params)); 
         } else { 
             curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$this->method); 
         } 
         if($this->contentType != null) { 
             curl_setopt($this->curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this->contentType)); 
         } 
         curl_setopt($this->curl,CURLOPT_URL,$this->url); 
         $r = curl_exec($this->curl); 
         $this->treatResponse($r); // Extract the headers and response 
         return $this ; 
     } 

     /** 
      * Treats URL 
      */ 
     private function treatURL(){ 
         if(is_array($this->params) && count($this->params) >= 1) { // Transform parameters in key/value pars in URL 
             if(!strpos($this->url,'?')) 
                 $this->url .= '?' ; 
             foreach($this->params as $k=>$v) { 
                 $this->url .= "&".urlencode($k)."=".urlencode($v); 
             } 
         } 
        return $this->url; 
     } 

     /* 
      * Treats the Response for extracting the Headers and Response 
      */  
     private function treatResponse($r) { 
        if($r == null or strlen($r) < 1) { 
            return; 
        } 
        $parts  = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body
        while(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0]) or preg_match("@Moved@",$parts[0])) { 
            // Continue header must be bypass 
            for($i=1;$i<count($parts);$i++) { 
                $parts[$i - 1] = trim($parts[$i]); 
            } 
            unset($parts[count($parts) - 1]); 
        } 
        preg_match("@Content-Type: ([a-zA-Z0-9-]+/?[a-zA-Z0-9-]*)@",$parts[0],$reg);// This extract the content type 
        $this->headers['content-type'] = $reg[1]; 
        preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message 
        $this->headers['code'] = $reg[1]; 
        $this->headers['message'] = $reg[2]; 
        $this->response = ""; 
        for($i=1;$i<count($parts);$i++) {//This make sure that exploded response get back togheter 
            if($i > 1) { 
                $this->response .= "\n\r"; 
            } 
            $this->response .= $parts[$i]; 
        } 
     } 

     /* 
      * @return array 
      */ 
     public function getHeaders() { 
        return $this->headers; 
     } 

     /* 
      * @return string 
      */  
     public function getResponse() { 
         return $this->response ; 
     } 

     /* 
      * HTTP response code (404,401,200,etc) 
      * @return int 
      */ 
     public function getResponseCode() { 
         return (int) $this->headers['code']; 
     } 

     /* 
      * HTTP response message (Not Found, Continue, etc ) 
      * @return string 
      */ 
     public function getResponseMessage() { 
         return $this->headers['message']; 
     } 

     /* 
      * Content-Type (text/plain, application/xml, etc) 
      * @return string 
      */ 
     public function getResponseContentType() { 
         return $this->headers['content-type']; 
     } 

     /** 
      * This sets that will not follow redirects 
      * @return RestClient 
      */ 
     public function setNoFollow() { 
         curl_setopt($this->curl,CURLOPT_AUTOREFERER,false); 
         curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false); 
         return $this; 
     } 

     /** 
      * This closes the connection and release resources 
      * @return RestClient 
      */ 
     public function close() { 
         curl_close($this->curl); 
         $this->curl = null ; 
         if($this->file !=null) { 
             fclose($this->file); 
         } 
         return $this ; 
     } 

     /** 
      * Sets the URL to be Called 
      * @return RestClient 
      */ 
     public function setUrl($url) { 
         $this->url = $url;  
         return $this; 
     } 

     /** 
      * Set the Content-Type of the request to be send 
      * Format like "application/xml" or "text/plain" or other 
      * @param string $contentType 
      * @return RestClient 
      */ 
     public function setContentType($contentType) { 
         $this->contentType = $contentType; 
         return $this; 
     } 

     /** 
      * Set the Credentials for BASIC Authentication 
      * @param string $user 
      * @param string $pass 
      * @return RestClient 
      */ 
     public function setCredentials($user,$pass) { 
         if($user != null) { 
             curl_setopt($this->curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); 
             curl_setopt($this->curl,CURLOPT_USERPWD,"{$user}:{$pass}"); 
         } 
         return $this; 
     } 

     /** 
      * Set the Request HTTP Method 
      * For now, only accepts GET and POST 
      * @param string $method 
      * @return RestClient 
      */ 
     public function setMethod($method) { 
         $this->method=$method; 
         return $this; 
     } 

     /** 
      * Set Parameters to be send on the request 
      * It can be both a key/value par array (as in array("key"=>"value")) 
      * or a string containing the body of the request, like a XML, JSON or other 
      * Proper content-type should be set for the body if not a array 
      * @param mixed $params 
      * @return RestClient 
      */ 
     public function setParameters($params) { 
         $this->params=$params; 
         return $this; 
     } 

     /** 
      * Creates the RESTClient 
      * @param string $url=null [optional] 
      * @return RestClient 
      */ 
     public static function createClient($url=null) { 
         $client = new RestClient ; 
         if($url != null) { 
             $client->setUrl($url); 
         } 
         return $client; 
     } 

     /** 
      * Convenience method wrapping a commom POST call 
      * @param string $url 
      * @param mixed params 
      * @param string $user=null [optional] 
      * @param string $password=null [optional] 
      * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default 
      * @return RestClient 
      */ 
     public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { 
         return self::call("POST",$url,$params,$user,$pwd,$contentType); 
     } 

     /** 
      * Convenience method wrapping a commom PUT call 
      * @param string $url 
      * @param string $body  
      * @param string $user=null [optional] 
      * @param string $password=null [optional] 
      * @param string $contentType=null [optional]  
      * @return RestClient 
      */ 
     public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { 
         return self::call("PUT",$url,$body,$user,$pwd,$contentType); 
     } 

     /** 
      * Convenience method wrapping a commom GET call 
      * @param string $url 
      * @param array params 
      * @param string $user=null [optional] 
      * @param string $password=null [optional] 
      * @return RestClient 
      */ 
     public static function get($url,array $params=null,$user=null,$pwd=null) { 
         return self::call("GET",$url,$params,$user,$pwd); 
     } 

     /** 
      * Convenience method wrapping a commom delete call 
      * @param string $url 
      * @param array params 
      * @param string $user=null [optional] 
      * @param string $password=null [optional] 
      * @return RestClient 
      */ 
     public static function delete($url,array $params=null,$user=null,$pwd=null) { 
         return self::call("DELETE",$url,$params,$user,$pwd); 
     } 

     /** 
      * Convenience method wrapping a commom custom call 
      * @param string $method 
      * @param string $url 
      * @param string $body  
      * @param string $user=null [optional] 
      * @param string $password=null [optional] 
      * @param string $contentType=null [optional]  
      * @return RestClient 
      */ 
     public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { 
         return self::createClient($url) 
             ->setParameters($body) 
             ->setMethod($method) 
             ->setCredentials($user,$pwd) 
             ->setContentType($contentType) 
             ->execute() 
             ->close(); 
     } 
} 

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:01:06+00:00Added an answer on May 25, 2026 at 2:01 pm

    Ran your code – only error I got was:

    Notice: Undefined variable: inputs
    

    Removing $inputs – no errors

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php code, which has been snipped for brevity. I am
I have the following PHP code which works out the possible combinations from a
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have the following code: if (include_once(dirname(__FILE__).'/file.php') || include_once(dirname(__FILE__).'/local/file.php') ) { This causes an
I have the following PHP code, but it's not working. I don't see any
I have the following PHP code, which is meant to insert data in the
I have the following PHP code which is attempting to check for password complexity
I have the following line of PHP code which works great: exec( 'wget http://www.mydomain.com/u1.php
I have following PHP code: if($_SESSION['msg']['login-err']) { echo '<p class=error>'.$_SESSION['msg']['login-err'].'</p>'; unset($_SESSION['msg']['login-err']); } Everything working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.