xmlrpc_encode_request
(PHP 4 >= 4.1.0, PHP 5, PHP 7)
xmlrpc_encode_request - 为方法请求生成XML
描述
string xmlrpc_encode_request ( string $method , mixed $params [, array $output_options ] )
警告
这个功能是实验性的。在将来的PHP版本中,此函数,其名称和周围文档的行为可能会在未经通知的情况下发生变化。应该使用此功能,风险自负。
参数
method
要调用的方法的名称。
params
方法参数与方法签名兼容。
output_options
指定输出选项的数组可能包含(强调默认值):
- output_type: php, xml
- verbosity: no_white_space, newlines_only, pretty
- escaping: cdata, non-ascii, non-print, markup ( 可能是一个具有一个值的字符串或具有多个值的数组 )
- version: simple, xmlrpc, soap 1.1, auto
- encoding: iso-8859-1, iconv支持的其他字符集
返回值
返回包含请求的XML表示的字符串。
例子
示例#1 XMLRPC客户端函数示例
<?php
$request = xmlrpc_encode_request("method", array(1, 2, 3));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));
$file = file_get_contents("http://www.example.com/xmlrpc", false, $context);
$response = xmlrpc_decode($file);
if ($response && xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
print_r($response);
}
?>
扩展内容
- stream_context_create() - 创建一个流上下文
- file_get_contents() - 将整个文件读入一个字符串
- xmlrpc_decode() - 将XML解码为本机PHP类型
← xmlrpc_decode
xmlrpc_encode →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com