0

I'm trying create XML request to remote server with CodeIgniter. I need create formatted call like this:

<?xml version="1.0" encoding="utf-8"?>
    <request name="get_packmachine">
      <auth username="test" password="test" />
    </request>

My current Code Igniter code:

                    $this->load->library('xmlrpc');

                    $this->xmlrpc->server($gate, 80);
                    $this->xmlrpc->method('get_packmachine');

                    $request = array('get_packmachine' => array('auth'=>array('username'=>'test','password'=>'test')));
                    $this->xmlrpc->request($request);

But it's returning still some errors. Is it possible make call like in my example with this CI library?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jiří Valoušek
  • 611
  • 1
  • 7
  • 19
  • Having spent (wasted?) hours upon hours creating correct payloads I found that a fast and neat way of not having to worry about the "array within an array comma 'struct'" format is to just JSON encode your data before sending and decode it upon reception, turning the array into a string. – Rid Iculous Jan 06 '17 at 00:27

1 Answers1

0

You can format your request like that:

$request = array(array( array('username'=>'test', 'password'=> 'test') ,'struct'));

If you pass an array you have to wrap is into another array with a 'struct' element. On the server side $parameter[0] will contain the desired data.

I must admit though that it looks kind of ugly but it does what it is supposed to do.

Johnny2k
  • 163
  • 1
  • 7