nasaplayer 发表于 2016-3-30 11:28:27

CI用XML-PRC收不到200返回信息

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

客户Xmlrpc_client.php
<?php

class Xmlrpc_client extends CI_Controller {

    public 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>';
      }
    }
}
?>




服务器端Xmlrpc_server.php

<?php
class Xmlrpc_server extends CI_Controller {

    public 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();
    }


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

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

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




nasaplayer 发表于 2016-3-31 12:00:38

找到原因了,路径请求有问题。
修改了config['base_url']中的值
$server_url = site_url('xmlrpc_server');

Hex 发表于 2016-4-1 14:44:34

nasaplayer 发表于 2016-3-31 12:00
找到原因了,路径请求有问题。
修改了config['base_url']中的值
$server_url = site_url('xmlrpc_server') ...

base_url 这个在 CI 3 里必须设置。
页: [1]
查看完整版本: CI用XML-PRC收不到200返回信息