0

我在服务器上运行它,使用 Joomla 的 XMLRPC for PHP 实现。无论我尝试发送什么 xmlrpcval(包括null)都不会发送。而是发送一个空数组。

相关主码。我尝试过发送不同种类的 xmlrpcmsg(从复杂的数组到简单的字符串):

$articleData = new xmlrpcmsg("insertContent", array(new xmlrpcval($articleArray, "struct")));
$client = new xmlrpc_client("/administrator/components/com_quickagencyslave/remote/easyblog.php", $clientArray["url"]);
$response = $client->send($articleData);

从属代码(不是实际功能,只是试图让它工作:

function insertContent($params){        
    $data = $params->getParam(0);
    $result = gettype($data);

    return new xmlrpcresp(new xmlrpcval($result));
}

返回码显示$data类型为NULL。我究竟做错了什么?

4

1 回答 1

1

As it turns out XMLRPC is very strict about what data it will accept (something that isn't entirely reflected in the docs). An array can't contain plain objects, even if that array has been converted into an XMLRPC object. The code below wraps an array and everything in it into an XMLRPC struct:

//Takes an array containing strings, returns an xmlrpc array of xmlrpcvals
function xmlrpcpack($input){
    if(is_array($input)){
        $return = array();
        foreach($input as $item){
            if(gettype($item) === "array")
                $return[] = xmlrpcpack($item);
            else
                $return[] = new xmlrpcval($item);
        }
        return new xmlrpcval($return, "array");
    }else{
        debug_print_backtrace();
    }
}
于 2012-07-17T13:41:46.187 回答