PHP: xmlrpc_encode_request - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

xmlrpc_encode xmlrpc_decode

Last updated: Sat, 27 Jan 2007

view this page in

# xmlrpc_encode_request

(PHP 4 >= 4.1.0, PHP 5)

xmlrpc_encode_request -- Generates XML for a method request

## Описание

string xmlrpc_encode_request ( string method, mixed params [, array output_options] )

Внимание
Эта функция является ЭКСПЕРИМЕНТАЛЬНОЙ. Поведение этой функции, ее имя и относящаяся к ней документация могут измениться в последующих версиях PHP без уведомления. Используйте эту функцию на свой страх и риск.

## Список параметров

`method`

  Name of the method to call.

`params`

  Method parameters compatible with method signature.

`output_options`

  Array specifying output options may contain (default values are emphasised):

  - output_type: php, xml

  - verbosity: no_white_space, newlines_only, pretty

  - escaping: cdata, non-ascii, non-print, markup (may be a string with one value or an array with multiple values)

  - version: simple, xmlrpc, soap 1.1, auto

  - encoding: iso-8859-1, other character set supported by iconv

## Возвращаемые значения

Returns a string containing the XML representation of the request.

## Примеры

Пример 1. XMLRPC client functions example

`<?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 (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
print_r($response);
}
?>`

## Смотрите также

stream_context_create()
file_get_contents()
xmlrpc_decode()

add a note User Contributed Notes
xmlrpc_encode_request
giunta dot gaetano at sea-aeroportimilano dot it
21-Aug-2006 03:54
`Take care that this function will generate invalid xmlrpc content when invoked with certain parameters (said content will be happily parsed by the lib itself, but not by other implementations).
xmlrpc_encode_request(null, null)
will generate a response without a value
xmlrpc_encode_request('myfunc', array('faultCode' => 666, 'faultString' => 'hello world')
will generated a request containing a <fault> member instead of <params>`
php at hendrik dash krauss dot de
28-May-2005 02:35
`For documentation and examples regarding the array output_options, see http://xmlrpc-epi.sourceforge.net/main.php?t=php_api#output_options
In short, output_options lets you send compact xmlrpc (without all the "pretty whitespace" xmlrpc_encode adds normally), apply an own escaping table prior to sending, set the encoding, and a couple of other things (the page even says something about soap 1.1 ... I don't know details).`
php at hendrik dash krauss dot de
28-May-2005 02:29
`For examples / documentation of the array output_options, see http://xmlrpc-epi.sourceforge.net/main.php?t=php_api#output_options
In short, output_options lets you send compact xmlrpc (without all the "pretty whitespace" xmlrpc_encode adds normally), apply an own escaping table prior to sending, set the encoding, and a couple of other things (the page even says something about soap 1.1 ... I don't know details).`
<URL:http://www.dlitz.net/go/contact/>
03-May-2004 11:28
`Note that as far as I can tell, the &#10; characters generated by PHP in the base64 fields don't appear to violate the XML-RPC standard at all. XML-RPC messages *are* in XML format, and as such, the XML entities should be getting decoded before being passed to a base64 decoder. So, the previously-mentioned Jakarta-based XML-RPC server appears to violate the XML spec. i.e. There's nothing here that needs to be "fixed" in PHP.`
Brian
09-Feb-2003 08:00
`As per documentation on xmlrpc-epi's site, this function
also can create both a methodCall and a methodResponse.
to create a methodCall:
xmlrpc_encode_request(null,$params);
to create a methodRequest:
xmlrpc_encode_request("methodName",$params);
---
The documentation on this is abysmal. I know this is opensource, but it has been around for quite a while now.`
kelly at seankelly dot biz
28-Dec-2002 04:02
`Binary strings (set with xmlrpc_set_type) go into a <base64>...</base64> block like you'd expect. But after every 80th character, this function inserts the XML entity "&#10;", which is a Unicode newline, as if to cause a line-wrap, which is admittedly silly.
Silly though it may be, it causes real problems for some XML-RPC servers, such as http://jakarta.apache.org/xmlrpc/ (nee Helma). Stripping out those entities with something like
$req = preg_replace('/&#10;/', '', xmlrpc_encode_request("my.method", $args));
works around the problem.`
hfuecks at pinkgoblin dot com
15-Aug-2002 09:06
`This function should be used by an XML-RPC client to create an XML payload for an XML-RPC request;
<?php
$params = "system.methodSignature";
$method = "system.methodHelp";
$request = xmlrpc_encode_request($method,$params);
echo ( $request );
?>
Produces;
<?xml version='1.0' encoding="iso-8859-1" ?>
<methodCall>
<methodName>system.methodHelp</methodName>
<params>
<param>
<value>
<string>system.methodSignature</string>
</value>
</param>
</params>
</methodCall>
The second argument recognises the type of variable and generates the correct XML-RPC structure. See xmlrpc_encode() for more details.`
add a note
xmlrpc_encode xmlrpc_decode

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST