Welcome Guest, Not a member yet? Register   Sign In
XML-RPC Help sending data...
#1

[eluser]the1rob[/eluser]
Ok, I've been chewing on this for a while, with no success. I went through all the documentation I could find...I even went through these forums.

My problem is this: I set up a xmlrpc server. Now I want to send data to it. The client and server talk to each other fine...I can pass a method with no problem.

The issue is when I try to populate the parameters...

Code:
$request = array(
    'PARAM1' => array($_POST['PARAM1DATA'],'string'),
    'PARAM2' => array($_POST['PARAM2DATA'],'string'),
    'PARAM3' => array($_POST['PARAM3DATA'],'string'),
    'PARAM4' => array($_POST['PARAM4DATA'],'string'),
    'PARAM5' => array($_POST['PARAM5DATA'],'string')
    );

$server_url = site_url('xmlrpc');    
$this->xmlrpc->server($server_url, 80);
$this->xmlrpc->method('sendpacket');
$this->xmlrpc->request($request);    

if ( ! $this->xmlrpc->send_request())
{
    log_message('debug', "hit if branch 1");
    echo $this->xmlrpc->display_error();
}
else
{
    log_message('debug', "hit else branch");
    echo '<pre>';
    print_r($this->xmlrpc->display_response());
    echo '</pre>';
}

Once I hit the send_request I get a bunch of PHP errors:

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: libraries/Xmlrpc.php

Line Number: 627


I get 4 of those, then...

Fatal error: Call to a member function serialize_class() on a non-object in /home/srwww/system/libraries/Xmlrpc.php on line 646

Sooo...something is wrong with my $request array. Can someone, ANYONE, please take a look and nudge me in the right direction? I'm dying here.





-t1r
#2

[eluser]gtech[/eluser]
I seem to rememeber (I havn't touched xml for about a year) that if you have an array in the XML request you need to have the keyword 'struct'.

example:
Code:
$this->xmlrpc->request(array(
                                    array(
                                          // Param 0
                                          array('test'=>'testdata'),
                                          'struct'
                                    ),
                                    array(
                                          // Param 1
                                          array('var1'=>'testdata2',
                                                'var2'=>'testdata3'),
                                          'struct'
                                    )
                               ),
                               'struct');
#3

[eluser]gtech[/eluser]
[url="http://ellislab.com/forums/viewthread/81915/"] This thread I posted just over a year ago should help [/url]

edit:

I havn't tested it.. but I think you want somthing like this:
Code:
$this->xmlrpc->request(array(
                           array(
                               // Param 0
                               $_POST['PARAM0DATA'],
                               'string'
                           ),
                           array(
                               // Param 1
                               $_POST['PARAM1DATA'],
                               'string'
                           )
                       ),
                       'struct');

the server might be somthing like:

Code:
function _process($request)
  {
    $parameters = $request->output_parameters();
    $response = array(
                     array(
                          'you_said'  => $parameters['0'],
                          'you_said2'  => $parameters['1'],
                          'i_respond' => 'Not bad at all.'
                     ),
                'struct');
    return $this->xmlrpc->send_response($response);
  }

the XMLRPC code uses an array to build up the request and the last element in the array tells the xml code what type of variable is contained in the array.

for example a string:
Code:
array('data','string')
an array is a struct
Code:
array(array('data','string'),array('data2','string'),'struct')
this can recurse down as you can see in the previous reply in this post.
#4

[eluser]the1rob[/eluser]
Holy crap that last trick worked!

Posting the code for future searches...

Client side:
Code:
$request = array(

array('test0','string'),
array('test1','string'),                  
array('test2','string'),                                          
array('test3','string'),                                      
array('test4','string')
,'struct');

Server side:
Code:
$parameters = $request->output_parameters();
$newvariable = $parameters['0'];  // newvariable = 'test0'
$newvariable2 = $parameters['1']; // newvariable2 = 'test1'


Worked perfectly! Server grabbed it and processed it perfectly on the first shot! Woohoo!

Thank you!
#5

[eluser]gtech[/eluser]
cool.. I love it when a plan comes together.. I remember it took me a while to figure out how to send arrays and assosiative arrays through XMLRPC so glad to save you the stress.




Theme © iAndrew 2016 - Forum software by © MyBB