|
我测试rpc,总是返回 This is not a known method for this XML-RPC Server。。折腾一下午了。找了好多资料看,有的说是ci的xmlrpc有bug啥的,也没说出个所以然来。rpc=人品差....
先看代码,RPC服务器方法
PHP复制代码 function server ()
{
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
// 设置接口方法集合
$config['functions']['Test'] = array('function' => 'link.test'); // 平台余额接口
$config['object'] = $this;
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
} 复制代码
再看客户端代码:PHP复制代码 function index ()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('method', 'Request method', 'required');
if ($this->form_validation->run() == false)
{
$this->load->view('index');
}
else
{
$post = $this->input->post(null, true);
$method = $post['method'];
unset($post['method']);
$request = json_encode($post);
$this->load->library('xmlrpc');
$server = site_url ('main/server');
$this->xmlrpc->server($server, 80);
$this->xmlrpc->method($method);
$this->xmlrpc->set_debug(true);
$request = array( $request);
//print_r($request);
$this->xmlrpc->request($request);
if (!$this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
else
{
echo $this->xmlrpc->display_response();
}
}
} 复制代码
然后在看客户端请求的方法,Link/test, 控制器文件名和类名均为大写PHP复制代码 function test ($request)
{
$this->load->library('xmlrpc');
$a = $request->output_parameters();
//log_message('error',var_export($request, true));
$a = json_decode($a[0]);
$response = array(a , 'struct');
return $this->xmlrpc->send_response($response);
} 复制代码 |
|