Welcome Guest, Not a member yet? Register   Sign In
Codeigniter XML-RPC Sample Code Issue
#1

[eluser]Unknown[/eluser]
Trying to run Codeigniter User Guide XML RPC Sample Code.

This is the code

xmlrpc_client.php

Code:
<?php

class Xmlrpc_client extends CI_Controller {

function index()
{
    $this->load->helper('url');
    $server_url = site_url('xmlrpc_server');

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

    $this->xmlrpc->server($server_url, 80);
    $this->xmlrpc->method('Greetings');

    $request = array('How is it going?');
    $this->xmlrpc->request($request);

    if ( ! $this->xmlrpc->send_request())
    {
        echo $this->xmlrpc->display_error();
    }
    else
    {
        echo '<pre>';
        print_r($this->xmlrpc->display_response());
        echo '</pre>';
    }
}}?&gt;
xmlrpc_server.php

Code:
&lt;?php

class Xmlrpc_server extends CI_Controller {

function index()
{
    $this->load->library('xmlrpc');
    $this->load->library('xmlrpcs');

    $config['functions']['Greetings'] = array('function' => 'Xmlrpc_server.process');

    $this->xmlrpcs->initialize($config);
    $this->xmlrpcs->serve();
}


function process($request)
{
    $parameters = $request->output_parameters();

    $response = array(
                        array(
                                'you_said'  => $parameters['0'],
                                'i_respond' => 'Not bad at all.'),
                        'struct');

    return $this->xmlrpc->send_response($response);
}}?&gt;
After this, i ran the url like this.

remoteserver's ip/xmlrpc_client

(i deleted my index.php using .htaccess, dont need to type it)

the result is like this,

Did not receive a '200 OK' response from remote server. (HTTP/1.1 404 Not Found)

If i run the server code, remoteserver's ip/xmlrpc_server it says like this.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

Which means,

$this->xmlrpc->send_request()

this request have been failed

and echoed

echo $this->xmlrpc->display_error();

Any idea what is the problem is?

Oh, i have another question.

Do i have to install xmlrpc php extension before i use this codeigniter xmlrpc class?
#2

[eluser]quickshiftin[/eluser]
It looks like you don't have to install any particular PHP extension as the XML-RPC implementation appears to be done entirely in PHP.

As far as what's wrong, it could be any number of things... As a starting point, I'd suggest inspecting the
Code:
$server_url
variable.

Try changing the code in xmlrpc_client.php to

Code:
$server_url = site_url('xmlrpc_server');
echo '<pre>';
var_dump($server_url);
die('</pre>');

Verify the IP is the same as your server. My guess is the client is getting pointed to the correct location.
#3

[eluser]Unknown[/eluser]
Thank you. the server's firewall rule was the problem. But my nextstage is

The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

This error Sad

If i print the debug msg. it shows like this.

---DATA---
HTTP/1.1 200 OK
Date: Thu, 18 Jul 2013 06:38:22 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Content-Length: 331
Connection: close
Content-Type: text/xml

678&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>you_said</name>
<value>
<string>How is it going?</string>
</value>
</member>
<member>
<name>i_respond</name>
<value>
<string>Not bad at all.</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END DATA---


where is this 678 coming from Sad
#4

[eluser]quickshiftin[/eluser]
Hmm, that could be a pain to track down. My suggestion, hack the system/libraries/Xmlrpcs.php file; edit the CI_Xmlrpcs class.

Change the serve function to this
Code:
function serve()
{  
    ob_start();
    $r = $this->parseRequest();
    ob_get_clean();

    $payload  = '&lt;?xml version="1.0" encoding="'.$this-&gt;xmlrpc_defencoding.'"?'.'>'."\n";
    $payload .= $this->debug_msg;
    $payload .= $r->prepare_response();

    header("Content-Type: text/xml");
    header("Content-Length: ".strlen($payload));
    exit($payload);
}

Now if there's any garbage coming from parseRequest it won't be sent to the output. If the 678 is still coming through it's before the call to serve.




Theme © iAndrew 2016 - Forum software by © MyBB