有没有熟悉CI XML-RPC的同学,求助
我测试rpc,总是返回 This is not a known method for this XML-RPC Server。。折腾一下午了。找了好多资料看,有的说是ci的xmlrpc有bug啥的,也没说出个所以然来。rpc=人品差....先看代码,RPC服务器方法
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();
}
再看客户端代码: 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, 控制器文件名和类名均为大写 function test ($request)
{
$this->load->library('xmlrpc');
$a = $request->output_parameters();
//log_message('error',var_export($request, true));
$a = json_decode($a);
$response = array(a, 'struct');
return $this->xmlrpc->send_response($response);
} 今天发现个,如果以上几个方法都写在一个控制器里,就可以请求数据返回数据。否则就提示方法不存在 xml-rpc我也弄過,
不過最後還是放棄使用,
改成使用samplexml這個類.
页:
[1]