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;
}
}
?>
Looking for the same solution. This is a super simple class that can theoretically work with any XMLRPC server. I whipped it up in 20 minutes, so there is still a lot to be desired such as introspection, some better error handling, etc.
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;
}
}
?>
发布评论
评论(8)
一个非常简单的xmlrpc客户端,我使用cURL类,你可以从: https://github.com/dcai/curl/blob/master/src/dcai/curl.php
A very simple xmlrpc client, I use a cURL class, you can get it from: https://github.com/dcai/curl/blob/master/src/dcai/curl.php
寻找相同的解决方案。 这是一个超级简单的类,理论上可以与任何 XMLRPC 服务器一起使用。 我在 20 分钟内就完成了它,所以还有很多需要改进的地方,比如内省、一些更好的错误处理等等。
Looking for the same solution. This is a super simple class that can theoretically work with any XMLRPC server. I whipped it up in 20 minutes, so there is still a lot to be desired such as introspection, some better error handling, etc.
我编写了一个简单的面向对象包装器,使其变得简单:
请参阅http://code.google.com/p/ripcord/wiki/RipcordClientManual 了解更多信息和下载链接。
I've written a simple Object Oriented wrapper which makes it as easy as:
See http://code.google.com/p/ripcord/wiki/RipcordClientManual for more information and a download link.
我在 http://code.runnable.com/UnEjkT04_CBwAAB4/how-to-create-a-xmlrpc-server-and-a-xmlrpc-client-for-php
在 webfaction api 中登录的示例
您将看到就像是:
I found this solution in http://code.runnable.com/UnEjkT04_CBwAAB4/how-to-create-a-xmlrpc-server-and-a-xmlrpc-client-for-php
Example for login in webfaction api
You will see something like:
Wordpress 有 XML-RPC.php 文件,看一下..它可能会有所帮助
Wordpress has XML-RPC.php file take a look at that.. it might help
此外,fxmlrpc(与
NativeSerializer
和NativeParser) 是
ext/xmlrpc
的薄包装。Additionally, fxmlrpc (when used with
NativeSerializer
andNativeParser
) is a thin wrapper aroundext/xmlrpc
.来自php官方链接 http://www.php.net/manual/en/ ref.xmlrpc.php 使用 steph 的示例(位于底部)作为起点。 他使用相同的服务器并且很容易设置。也就是说,如果您不想使用外部库或框架。 但如果您这样做,请查看 http://framework。 zend.com/manual/1.12/en/zend.xmlrpc.server.html
From the php official link http://www.php.net/manual/en/ref.xmlrpc.php use steph 's example (at the bottom) as a starting point. He is using the same server and its easy to set up.That is if you do not wish to use the external library or framework. But if you do then have a look at http://framework.zend.com/manual/1.12/en/zend.xmlrpc.server.html
用 php 编写的客户端和服务器:
https://tldp.org /HOWTO/XML-RPC-HOWTO/xmlrpc-howto-php.html
Client and server written in php:
https://tldp.org/HOWTO/XML-RPC-HOWTO/xmlrpc-howto-php.html