ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Parse XML-RPC Server Response

July 29, 2011 3:34pm

Subscribe [2]
  • #1 / Jul 29, 2011 3:34pm

    SOVEREIGN

    3 posts

    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:

    // 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><p>‘;<br />
            }<br />
            <br />
            <br />
        }<br />
        <br />
        <br />
        // The XML Response Function<br />
        public function echo_back($request) {<br />
            <br />
            $parameters = $request->output_parameters();</p>
    
    <p>        $response = array(<br />
                                array(<br />
                                        'You sent to me:'  => $parameters['0'],<br />
                                        'And: '                  => $parameters['1']),<br />
                                'struct');</p>
    
    <p>        return $this->xmlrpc->send_response($response);<br />
            <br />
        }
    </pre>

    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:

    $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 / Jul 29, 2011 3:50pm

    SOVEREIGN

    3 posts

    I already done it using a foreach loop:

    $r = $this->xmlrpc->display_response();
    
                foreach ($r as $y=>$value) {
                    echo 'segment1: (' . $y . ') and segment2: (' . $value .')
    ';
                }

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

  • #3 / Jul 30, 2011 11:42am

    SOVEREIGN

    3 posts

    Nobody knows an alternative to do this?

    Anyone?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases