本文整理汇总了PHP中xmlrpc_encode_request函数的典型用法代码示例。如果您正苦于以下问题:PHP xmlrpc_encode_request函数的具体用法?PHP xmlrpc_encode_request怎么用?PHP xmlrpc_encode_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlrpc_encode_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($method, $parameters = null)
{
$request = xmlrpc_encode_request($method, $parameters);
$headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
if ($this->timeout) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
}
$rawResponse = curl_exec($curl);
$curlErrno = curl_errno($curl);
$curlError = curl_error($curl);
curl_close($curl);
if ($curlErrno) {
throw new NetworkException($curlError, $curlErrno);
}
$result = xmlrpc_decode($rawResponse);
if (xmlrpc_is_fault($result)) {
throw new NetworkException($result['faultString'], $result['faultCode']);
}
return $result;
}
示例2: callRemote
function callRemote($method)
{
// Curl is required so generate a fault if curl functions cannot be found.
if (!$this->curl) {
return array('faultCode' => -1, 'faultString' => 'Curl functions are unavailable.');
}
// The first argument will always be the method name while all remaining arguments need
// to be passed along with the call.
$args = func_get_args();
array_shift($args);
if ($this->xmlrpc) {
// If php has xmlrpc support use the built in functions.
$request = xmlrpc_encode_request($method, $args);
$result = $this->__xmlrpc_call($request);
$decodedResult = xmlrpc_decode($result);
} else {
// If no xmlrpc support is found, use the phpxmlrpc library. This involves containing
// all variables inside the xmlrpcval class.
$encapArgs = array();
foreach ($args as $arg) {
$encapArgs[] = $this->__phpxmlrpc_encapsulate($arg);
}
$msg = new xmlrpcmsg($method, $encapArgs);
$client = new xmlrpc_client($this->url);
$client->verifypeer = false;
$result = $client->send($msg);
if ($result->errno) {
$decodedResult = array('faultCode' => $result->errno, 'faultString' => $result->errstr);
} else {
$decodedResult = php_xmlrpc_decode($result->value());
}
}
return $decodedResult;
}
示例3: get_request
static function get_request($method, $params = CJ_EMPTY_VALUE, $params2 = CJ_EMPTY_VALUE, $params3 = CJ_EMPTY_VALUE, $params4 = CJ_EMPTY_VALUE, $params5 = CJ_EMPTY_VALUE)
{
if ($params == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array(), array('encoding' => 'utf8'));
} else {
if ($params2 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params), array('encoding' => 'utf8'));
} else {
if ($params3 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2), array('encoding' => 'utf8'));
} else {
if ($params4 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3), array('encoding' => 'utf8'));
} else {
if ($params5 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3, $params4), array('encoding' => 'utf8'));
} else {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3, $params4, $params5), array('encoding' => 'utf8'));
}
}
}
}
}
return $request;
}
示例4: rpc_send
/**
* send xml data to OpenNebula RPC server
* @param $method
* @param $argument
*/
function rpc_send($method, $argument)
{
//Using the XML-RPC extension to format the XML package
$request = xmlrpc_encode_request($method, $argument);
$req = curl_init($this->service_url);
//Using the cURL extension to send it off, first creating a custom header block
$headers = array();
array_push($headers, "Content-Type: text/xml");
array_push($headers, "Content-Length: " . strlen($request));
array_push($headers, "\r\n");
//URL to post to
curl_setopt($req, CURLOPT_URL, $this->service_url);
//Setting options for a secure SSL based xmlrpc server
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($req, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($req, CURLOPT_HTTPHEADER, $headers);
curl_setopt($req, CURLOPT_POSTFIELDS, $request);
//Finally run
$response = curl_exec($req);
//Close the cURL connection
curl_close($req);
//Decoding the response to be displayed
$result = xmlrpc_decode($response);
return $result;
}
示例5: get_request
static function get_request($method, $params = CJ_EMPTY_VALUE, $params2 = CJ_EMPTY_VALUE, $params3 = CJ_EMPTY_VALUE, $params4 = CJ_EMPTY_VALUE, $params5 = CJ_EMPTY_VALUE)
{
$comp_params = JComponentHelper::getParams('com_joomdle');
switch ($comp_params->get('moodle_version')) {
case 20:
if ($params == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array(), array('encoding' => 'utf8'));
} else {
if ($params2 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params), array('encoding' => 'utf8'));
} else {
if ($params3 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2), array('encoding' => 'utf8'));
} else {
if ($params4 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3), array('encoding' => 'utf8'));
} else {
if ($params5 == CJ_EMPTY_VALUE) {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3, $params4), array('encoding' => 'utf8'));
} else {
$request = xmlrpc_encode_request("joomdle_" . $method, array($params, $params2, $params3, $params4, $params5), array('encoding' => 'utf8'));
}
}
}
}
}
break;
case 19:
$request = xmlrpc_encode_request("auth/joomdle/auth.php/{$method}", array($params, $params2, $params3, $params4, $params5));
//, array ('encoding' => 'utf8'));
break;
}
return $request;
}
示例6: __call
public function __call($method, $params)
{
if (!function_exists('xmlrpc_encode_request')) {
throw new \Exception("The php5-xmlrpc extension is not installed. Please install this to use this functionality");
}
$xml = xmlrpc_encode_request($method, $params);
//\GO::debug($xml);
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_SSL_VERIFYPEER, false);
curl_setopt($this->curl_hdl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->curl_hdl, CURLOPT_TIMEOUT, 10);
if (isset($this->_user)) {
curl_setopt($this->curl_hdl, CURLOPT_USERPWD, $this->_user . ":" . $this->_pass);
}
}
curl_setopt($this->curl_hdl, CURLOPT_POSTFIELDS, $xml);
// Invoke RPC command
$response = curl_exec($this->curl_hdl);
$errorNo = curl_errno($this->curl_hdl);
if ($errorNo) {
throw new \Exception($this->_curlErrorCodes[$errorNo]);
}
//\GO::debug($response);
$result = xmlrpc_decode_request($response, $method);
return $result;
}
示例7: serialize
/** {@inheritdoc} */
public function serialize($method, array $params = [])
{
$toBeVisited = [&$params];
while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
$type = gettype($value);
if ($type === 'array') {
foreach ($value as &$child) {
$toBeVisited[] =& $child;
}
} elseif ($type === 'object') {
if ($value instanceof DateTime) {
$value = $value->format('Ymd\\TH:i:s');
xmlrpc_set_type($value, 'datetime');
} elseif ($value instanceof Base64Interface) {
$value = $value->getDecoded();
xmlrpc_set_type($value, 'base64');
} else {
$value = get_object_vars($value);
}
} elseif ($type === 'resource') {
throw SerializationException::invalidType($value);
}
array_shift($toBeVisited);
}
return xmlrpc_encode_request($method, $params, ['encoding' => 'UTF-8', 'escaping' => 'markup', 'verbosity' => 'no_white_space']);
}
示例8: onStartNoticeSave
function onStartNoticeSave($notice)
{
$args = $this->testArgs($notice);
common_debug("Blogspamnet args = " . print_r($args, TRUE));
$request = xmlrpc_encode_request('testComment', array($args));
$context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml\r\n" . "User-Agent: " . $this->userAgent(), 'content' => $request)));
$file = file_get_contents($this->baseUrl, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
} else {
common_debug("Blogspamnet results = " . $response);
if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
} else {
if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
} else {
if (preg_match('/^OK$/', $response)) {
// don't do anything
} else {
throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
}
}
}
}
return true;
}
示例9: xmlrpc_request
function xmlrpc_request($host, $port, $location, $function, &$request_data)
{
/*
* This method sends a very basic XML-RPC request. $host, $port, $location,
* and $function are pretty simple. $request_data can be any PHP type,
* and this function returns the PHP type of whatever the xmlrpc function
* returns.
*
* WARNING: This function dies upon failure.
*/
// Send request
$request_xml = xmlrpc_encode_request($function, $request_data);
// Split out response into headers, and xml
$response = urlpost($host, $port, $location, $request_xml);
$response_array = split("\r\n\r\n", $response, 2);
$response_headers = split("\r\n", $response_array[0]);
$response_xml = $response_array[1];
$http_array = split(" ", $response_headers[0], 3);
if ($http_array[1] != "200") {
trigger_error("xmlrpc request failed: ({$http_array[1]}, {$http_array[2]}) at {$host}:{$port} using {$location}");
} else {
// Get native PHP types and return them for data.
$response_data = xmlrpc_decode_request($response_xml, $function);
return $response_data;
}
}
示例10: sendRequest
/**
* @method sendRequest
* @param string $remoteMethod
* @param array $params
* @return HttpRequest_Response_Xml
*/
public function sendRequest($remoteMethod, array $params)
{
$this->error = NULL;
$request = xmlrpc_encode_request($remoteMethod, $params);
$this->body = $request;
return $this->request('CUSTOMPOST', $request);
}
示例11: _call
/**
* Provede volani funkce na captcha server
*
* @param string $methodName nazev metody
* @param array $params parametry
*
* @return mixed vysledek volani
*/
protected function _call($methodName, $params = [])
{
if (!function_exists('xmlrpc_encode_request')) {
throw new Exception("PHP XMLRPC extension neni nainstalovana");
}
$ch = curl_init(sprintf('http://%s:%d', $this->_serverHostname, $this->_serverPort));
if (!$ch) {
throw new Exception("Chyba volani curl_init");
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
if ($this->_proxyHostname) {
curl_setopt($ch, CURLOPT_PROXY, $this->_proxyHostname);
curl_setopt($ch, CURLOPT_PROXYPORT, $this->_proxyPort);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: text/xml", "charset=UTF-8"]);
$request = xmlrpc_encode_request($methodName, $params, ['encoding' => 'UTF-8']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
if ($response === FALSE) {
throw new Exception("Chyba volani curl_exec");
}
$info = curl_getinfo($ch);
if ($info['http_code'] != 200) {
throw new Exception("Chyba volani curl_exec. HTTP status code " . $info['http_code']);
}
$response = xmlrpc_decode($response, 'UTF-8');
if (empty($response) || xmlrpc_is_fault($response)) {
throw new Exception(sprintf("XMLRPC error: %s", print_r($response, TRUE)));
}
return $response;
}
示例12: onStartNoticeSave
function onStartNoticeSave($notice)
{
$args = $this->testArgs($notice);
common_debug("Blogspamnet args = " . print_r($args, TRUE));
$requestBody = xmlrpc_encode_request('testComment', array($args));
$request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
$request->setHeader('Content-Type', 'text/xml');
$request->setBody($requestBody);
$httpResponse = $request->send();
$response = xmlrpc_decode($httpResponse->getBody());
if (xmlrpc_is_fault($response)) {
throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
} else {
common_debug("Blogspamnet results = " . $response);
if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
} else {
if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
} else {
if (preg_match('/^OK$/', $response)) {
// don't do anything
} else {
throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
}
}
}
}
return true;
}
示例13: ping
/**
* Ping Blog Update Services
*
* @param array $options are name, website, url
*/
function ping($options = array())
{
$type = 'REST';
if (function_exists('xmlrpc_encode_request')) {
$type = 'XML-RPC';
}
switch ($type) {
case 'REST':
// construct parameters
$params = array('name' => $options['name'], 'url' => $options['url']);
$params = array_map('rawurlencode', $params);
$paramString = http_build_query($params);
// Rest Update Ping Services
foreach ($this->__services['rest'] as $serviceApi) {
$requestUrl = $serviceApi . '?' . $paramString;
$response = file_get_contents($requestUrl);
}
break;
case 'XML-RPC':
// construct parameters
$params = array($options['name'], $options['website'], $options['url'], $options['feed']);
$request = xmlrpc_encode_request("weblogUpdates.extendedPing", $params);
$context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
foreach ($this->__services['rpc'] as $endPoint) {
// Ping the services
$file = file_get_contents($endPoint, false, $context);
$response = xmlrpc_decode($file);
//no need to process the response
}
break;
}
}
示例14: rpc_call
/**
* rpc_call function.
*
* @access public
* @param string $method. (default: '')
* @param array $params. (default: array())
* @return void
*/
function rpc_call($method = '', $params = array())
{
$request = new WP_Http();
if (function_exists('xmlrpc_encode_request')) {
$params = xmlrpc_encode_request($method, $params);
}
return $request->request($this->getServiceUrl(), array('method' => 'POST', 'body' => $params));
}
示例15: send
/**
* Sends an XML RPC request to the XML RPC server
* @param $methodName string Name of the XML RPC method to call
* @param $params array Array of parameters to pass to the XML RPC method. Type is detected automatically. For a struct just encode an array within $params.
* @return array Array of returned parameters
*/
public function send($methodName, $params)
{
$request = xmlrpc_encode_request($methodName, $params);
$response = $this->sendRequest($request);
$response = xmlrpc_decode(trim($response));
//Without the trim function returns null
return $response;
}