• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parse XML-RPC Server Response

#1
[eluser]SOVEREIGN[/eluser]
I've been testing the XML-RPC CodeIgniter class, it's pretty good, buy i don't
have any idea of how the parse the response i get from the webservice server.

I'm using the sample code given in the documentation to create server and client:

Client:

Code:
// The Server
    public function xml_server() {
        $this->load->library(');
        $this->load->library(');
        
        $config['functions']['] = array('function'     => 'Welcome.echo_back);

        $config['object'] = $this;

        $this->xmlrpc->initialize($config);
        $this->xmlrpc->serve();
        
        
        
    }
    
    
    // The Client
    public function xml_client() {
        $this->load->library(');
        
        $this->xmlrpc->server('http://localhost/scripts/ci_rest/client/index.php/welcome/xml_server/', 80);
        $this->xmlrpc->method(');
        $this->xmlrpc->set_debug(TRUE);


        $request = array('Message from Sov', 'Hi dude');
        
        $this->xmlrpc->request($request);

        if ( ! $this->xmlrpc->send_request())
        {
            echo $this->xmlrpc->display_error();
        }
        else
        {    
            echo '<hr>';
            
            echo '<pre>';
            print_r($this->xmlrpc->display_response());
            echo '</pre>';
        }
        
        
    }
    
    
    // The XML Response Function
    public function echo_back($request) {
        
        $parameters = $request->output_parameters();

        $response = array(
                            array(
                                    'You sent to me:'  => $parameters['0'],
                                    'And: '                  => $parameters['1']),
                            'struct');

        return $this->xmlrpc->send_response($response);
        
    }

With the above example, it shows the response received from the server, buy i would like to know how to store the response in a array or some variables.

The XML-RPC client print this to the browser:

Array
(
[you_said] => Hi dude?
[i_respond] => Hi there friend.
)

How do i store that values in a variable?

I tried like this:

Code:
$r = $this->xmlrpc->display_response();
print_r($r);
            
$d = xmlrpc_decode($r['[you_said]']);
print_r($d);

But doesn't works.


Is that possible? Sorry if it's a newbie question, but im new to this protocol.

#2
[eluser]SOVEREIGN[/eluser]
I already done it using a foreach loop:

Code:
$r = $this->xmlrpc->display_response();

            foreach ($r as $y=>$value) {
                echo 'segment1: (' . $y . ') and segment2: (' . $value .')<br />';
            }

It works fine, but if anyone knows another way, please tell it.

#3
[eluser]SOVEREIGN[/eluser]
Nobody knows an alternative to do this?

Anyone?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.