我正在将旧的xmlrpc库转换为CI,以便在较大的项目中使用,但是当旧库运行时,我的转换不起作用。
旧库如下:
$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "reportuser",
"reportuser");
function reportuser($method_name, $params, $app_data)
{
global $db;
$req = $params[0];
$regionName = (string)$req['regionName'];
$abuserID = (string)$req['abuserID'];
$catagory = (int)$req['catagory'];
$checkflags = (int)$req['checkflags'];
$details = (string)$req['details'];
$objectID = (string)$req["objectID"];
$postion = (string)$req['postion'];
$reportType = (int)$req['reportType'];
$screenshotID = (string)$req['screenshotID'];
$Summary = (string)$req['Summary'];
$reporter = (string)$req['reporter'];
$query = $db->prepare("INSERT INTO reports VALUES (NULL, NOW(), '$regionName', '$abuserID', $catagory, $checkflags, '$details', '$objectID', '$postion', $reportType, '$screenshotID', '$Summary', '$reporter')");
$result = $query->execute();
$response_xml = xmlrpc_encode(array(
'success' => $result,
'errorMessage' => get_error_message($result)
));
print $response_xml;
}
$request_xml = file_get_contents("php://input");
xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
xmlrpc_server_destroy($xmlrpc_server);
我在控制器中内置的新测试库如下:
public function index()
{
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
$config['functions']['reportuser'] = array('function' => 'Report.reportuser');
$config['object'] = $this;
$config['xss_clean'] = FALSE;
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}
public function reportuser($request)
{
$this->load->library('xmlrpc');
$zsite = $this->load->database('grid', TRUE);
$parameters = $request->output_parameters();
$data = $parameters;
$zsite->query("INSERT INTO TEST VALUES ('$data')");
$params = $parameters[0];
$regionName = (string)$params['regionName'];
$abuserID = (string)$params['abuserID'];
$category = (int)$params['catagory'];
$checkflags = (int)$params['checkflags'];
$details = (string)$params['details'];
$objectID = (string)$params["objectID"];
$position = (string)$params['postion'];
$reportType = (int)$params['reportType'];
$screenshotID = (string)$params['screenshotID'];
$Summary = (string)$params['Summary'];
$reporter = (string)$params['reporter'];
$result = $zsite->query("INSERT INTO reports VALUES (NULL, NOW(), '$regionName', '$abuserID', '$category', '$checkflags', '$details', '$objectID', '$position', '$reportType', '$screenshotID', '$Summary', '$reporter')");
$response = array(
array(
'success' => $result,
'errorMessage' => get_error_message($result),
'struct'));
return $this->xmlrpc->send_response($response);
}
从客户端发出请求时,它返回一个错误,声称缺少Root元素:
无法连接到用户报告服务器。方法reportuser,参数为System.Collections.Hashtable。 System.Xml.XmlException异常:根元素丢失。
实际的插入查询和原始输入数据查询都没有执行,因此在此之前代码必须失败,但是我不知道为什么。 CI文档也没有提供太多信息来说明为什么它会引发错误,我唯一能找到的就是在服务器的access.log内部,显示为:“ POST / Report / reportuser / HTTP / 1.1” 200 31“-” “-”,尽管这是否表示它确实未接收任何数据,或者对于xmlrpc这是正常的,我不知道。
是否有什么我想念的内容或者语法上的错误?有什么方法可以获取原始数据,以便我查看它的格式?