PHP5 için örnek XML-RPC istemci kodu gerekir

6 Cevap php

XML-RPC istemci için PHP yerleşik XML-RPC kitaplığı (sürüm PHP Version 5.2.6) kullanmak için nasıl bir öğretici veya bazı öğretilmesi gerekir. Sunucu Python ve çalışıyor.

Google ve php.net beni başarısız oluyor.

Update:

Phpinfo başına I xmlrpc-epi v. 0.51 yüklediniz. Ben ziyaret http://xmlrpc-epi.sourceforge.net/ ama soldaki xmlrpc-epi-php örnekler bölümünde bana bir 404 sf.net 'ın versiyonunu gösterdi.

Update2:

I http://phpxmlrpc.sourceforge.net/ kullanmak ve umarım bu benim için çalışacaktır gidiyorum.

Update3:

At kod http://phpxmlrpc.sourceforge.net/ açıktı ve ben çalışma var.

Soruyu kapatmak değil. Herkes ultra basit çözümlerle uymak istiyorsa, bu harika olurdu!

6 Cevap

https://github.com/dongsheng/cURL/blob/master/curl.class.php: Ben bir cURL sınıf çok basit xmlrpc istemcisi kullanıyorsanız, onu alabilirsiniz

class xmlrpc_client {
    private $url;
    function __construct($url, $autoload=true) {
        $this->url = $url;
        $this->connection = new curl;
        $this->methods = array();
        if ($autoload) {
            $resp = $this->call('system.listMethods', null);
            $this->methods = $resp;
        }
    }
    public function call($method, $params = null) {
        $post = xmlrpc_encode_request($method, $params);
        return xmlrpc_decode($this->connection->post($this->url, $post));
    }
}
header('Content-Type: text/plain');
$rpc = "http://10.0.0.10/api.php";
$client = new xmlrpc_client($rpc, true);
$resp = $client->call('methodname', array());
print_r($resp);

Aynı çözüm arıyor. Bu teorik olarak herhangi XMLRPC sunucusu ile çalışabilir bir süper basit bir sınıftır. Ben 20 dakika içinde o kadar çırpılmış, bu yüzden vb iç gözlem, biraz daha iyi hata işleme olarak arzulanan bir çok şey var

file: xmlrpcclient.class.php

<?php

/**
 * XMLRPC Client
 *
 * Provides flexible API to interactive with XMLRPC service. This does _not_
 * restrict the developer in which calls it can send to the server. It also
 * provides no introspection (as of yet).
 *
 * Example Usage:
 *
 * include("xmlrpcclient.class.php");
 * $client = new XMLRPCClient("http://my.server.com/XMLRPC");
 * print var_export($client->myRpcMethod(0));
 * $client->close();
 *
 * Prints:
 * >>> array (
 * >>>   'message' => 'RPC method myRpcMethod invoked.',
 * >>>   'success' => true,
 * >>> )
 */

class XMLRPCClient
{
    public function __construct($uri)
    {
        $this->uri = $uri;
        $this->curl_hdl = null;
    }

    public function __destruct()
    {
        $this->close();
    }

    public function close()
    {
        if ($this->curl_hdl !== null)
        {
            curl_close($this->curl_hdl);
        }
        $this->curl_hdl = null;
    }

    public function setUri($uri)
    {
        $this->uri = $uri;
        $this->close();
    }

    public function __call($method, $params)
    {
        $xml = xmlrpc_encode_request($method, $params);

        if ($this->curl_hdl === null)
        {
            // Create cURL resource
            $this->curl_hdl = curl_init();

            // Configure options
            curl_setopt($this->curl_hdl, CURLOPT_URL, $this->uri);
            curl_setopt($this->curl_hdl, CURLOPT_HEADER, 0); 
            curl_setopt($this->curl_hdl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($this->curl_hdl, CURLOPT_POST, true);
        }

        curl_setopt($this->curl_hdl, CURLOPT_POSTFIELDS, $xml);

        // Invoke RPC command
        $response = curl_exec($this->curl_hdl);

        $result = xmlrpc_decode_request($response, $method);

        return $result;
    }
}

?>

Ben o kadar kolay kılan basit bir Object Oriented sarıcı yazdık:

    require_once('ripcord.php');
    $client = ripcord::xmlrpcClient( $url );
    $score  = $client->method( $argument, $argument2, .. );

http://code.google.com/p/ripcord/wiki/RipcordClientManual daha fazla bilgi ve indirme bağlantısı için bkz.

Wordpress XML-RPC.php dosya, o bakmak var .. o yardımcı olabilir

Ayrıca, fxmlrpc etrafında ince bir sarıcı (NativeSerializer ve NativeParser ile kullanıldığında) ext/xmlrpc.

Php resmi bağlantısından http://www.php.net/manual/en/ref.xmlrpc.php, bir başlangıç ​​noktası olarak (altta) steph 'nin örnek kullanacağız. O aynı sunucuyu kullanan ve harici kitaplık veya çerçeve kullanmak istemiyorsanız up.That set onun kolaydır. Ama daha sonra http://framework.zend.com/manual/1.12/en/zend.xmlrpc.server.html bakabilirsiniz yoksa