客户端发送的请求类似这样

  • 栏目:编程 时间:2020-02-16 21:45
<返回列表

客户端发送的请求类似这样
复制代码 代码如下:
$request = array('parameters00','parameters01');

复制代码 代码如下:

在客户端的请求你可以制定参数的数据类型,你可以将每个参数单独的放进一个数组,在数组的第二个位置制定参数的数据类型,类似这样
复制代码 代码如下:
$request = array(
array('parameters00','string'),
array('parameters01','boolean'),
array('parameters02','struct'),
array('parameters03','int'),
);

rn" . $xml_serialized_string; return $xml_serialized_string; }else{ return $xml_serialized_string; } } class XML { var $parser; #a reference to the XML parser var $document; #the entire XML structure built up so far var $current; #a pointer to the current item - what is this var $parent; #a pointer to the current parent - the parent will be an array var $parents; #an array of the most recent parent at each level var $last_opened_tag; function XML{ $this->parser = xml_parser_create(); xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object; xml_set_element_handler($this->parser, "open", "close"); xml_set_character_data_handler($this->parser, "data"); # register_shutdown_function(array; } function destruct(){ xml_parser_free; } function parse{ $this->document = array(); $this->parent = $this->document; $this->parents = array(); $this->last_opened_tag = NULL; xml_parse; return $this->document; } function open($parser, $tag, $attributes){ #echo "Opening tag $tag
n"; $this->data = ""; $this->last_opened_tag = $tag; #tag is a string if(array_key_exists{ #echo "There's already an instance of '$tag' at the current level
n"; if(is_array and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric #need to make sure they're numeric (account for attributes) $key = count_numeric_items; #echo "There are $key instances: the keys are numeric.
n"; }else{ #echo "There is only one instance. Shifting everything around
n"; $temp = $this->parent[$tag]; unset; $this->parent[$tag][0] = $temp; if(array_key_exists("$tag attr", $this->parent)){ #shift the attributes around too if they exist $temp = $this->parent["$tag attr"]; unset($this->parent["$tag attr"]); $this->parent[$tag]["0 attr"] = $temp; } $key = 1; } $this->parent = $this->parent[$tag]; }else{ $key = $tag; } if{ $this->parent["$key attr"] = $attributes; } $this->parent[$key] = array(); $this->parent = $this->parent[$key]; array_unshift($this->parents, $this->parent); } function data{ #echo "Data is '", htmlspecialchars, "'
n"; if($this->last_opened_tag != NULL){ $this->data .= $data; } } function close{ #echo "Close tag $tag
n"; if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_shift; $this->parent = $this->parents[0]; } } function & XML_unserialize{ $xml_parser = new XML(); $data = $xml_parser->parse; $xml_parser->destruct(); return $data; } function & XMLRPC_parse{ if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_parse', "

服务端的返回response有一点硬性的要求,必须要格式化数组,并且在response数组中必须只有一个主数组,类似这样:
复制代码 代码如下:
$response = array(
array(parameters00 => array('para00','string'),
parameters01 => array('para01','struct'),
parameters02 => array('para02','boolean'),
),'struct');

Received the following raw request:

如果你要使用关联数组需要注意一下,要注意关联数组的类型制定问题,类似这样:
复制代码 代码如下:
$request = array(
韦德体育 ,array(
'parameters00' => array(array('paraoo' => 'value'),'struct'),
'parameters01' => array('para01','string'),
),'struct'
);

" . XMLRPC_show($request, 'print_r', true)); } $data = &XML_unserialize; if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_parse', "

Returning the following parsed request:

" . XMLRPC_show($data, 'print_r', true)); } return $data; } function & XMLRPC_prepare{ if{ $num_elements = count; if((array_key_exists or !$num_elements) and $type != 'struct'){ #it's an array if{ #if the array is emptyempty $returnvalue = array('array' => array; }else{ $returnvalue['array']['data']['value'] = array(); $temp = $returnvalue['array']['data']['value']; $count = count_numeric_items; for($n=0; $n $key, 'value' => XMLRPC_prepare; } } } } }else{ #it's a scalar if{ if{ $returnvalue['int'] = $data; return $returnvalue; }elseif{ $returnvalue['double'] = $data; return $returnvalue; }elseif{ $returnvalue['boolean'] = ; return $returnvalue; }elseif(preg_match('/^d{8}Td{2}:d{2}:d{2}$/', $data, $matches)){ #it's a date $returnvalue['dateTime.iso8601'] = $data; return $returnvalue; }elseif{ $returnvalue['string'] = htmlspecialchars; return $returnvalue; } }else{ $returnvalue[$type] = htmlspecialchars; } } return $returnvalue; } function & XMLRPC_adjustValue{ if(is_array{ if(isset($current_node['array'])){ if(!is_array($current_node['array']['data'])){ #If there are no elements, return an emptyempty array return array(); }else{ #echo "Getting rid of array -> data -> value
n"; $temp = $current_node['array']['data']['value']; if and array_key_exists{ $count = count; for{ $temp2[$n] = &XMLRPC_adjustValue; } $temp = $temp2; }else{ $temp2 = &XMLRPC_adjustValue; $temp = array; #I do the temp assignment because it avoids copying, # since I can put a reference in the array #PHP's reference model is a bit silly, and I can't just say: # $temp = array(&XMLRPC_adjustValue; } } }elseif(isset($current_node['struct'])){ if(!is_array($current_node['struct'])){ #If there are no members, return an emptyempty array return array(); }else{ #echo "Getting rid of struct -> member
n"; $temp = $current_node['struct']['member']; if and array_key_exists{ $count = count; for{ #echo "Passing name {$temp[$n][name]}. Value is: " . show($temp[$n][value], var_dump, true) . "
n"; $temp2[$temp[$n]['name']] = &XMLRPC_adjustValue; #echo "adjustValue(): After assigning, the value is " . show($temp2[$temp[$n]['name']], var_dump, true) . "
n"; } }else{ #echo "Passing name $temp[name]
n"; $temp2[$temp['name']] = &XMLRPC_adjustValue; } $temp = $temp2; } }else{ $types = array('string', 'int', 'i4', 'double', 'dateTime.iso8601', 'base64', 'boolean'); $fell_through = true; foreach{ if(array_key_exists){ #echo "Getting rid of '$type'
n"; $temp = $current_node[$type]; #echo "adjustValue(): The current node is set with a type of $type
n"; $fell_through = false; break; } } if{ $type = 'string'; #echo "Fell through! Type is $type
n"; } switch { case 'int': case 'i4': $temp = $temp; break; case 'string': $temp = $temp; break; case 'double': $temp = $temp; break; case 'boolean': $temp = $temp; break; } } }else{ $temp = $current_node; } return $temp; } function XMLRPC_getParams{ if(!is_array($request['methodCall']['params'])){ #If there are no parameters, return an emptyempty array return array(); }else{ #echo "Getting rid of methodCall -> params -> param
n"; $temp = $request['methodCall']['params']['param']; if and array_key_exists{ $count = count; for($n = 0; $n < $count; $n++){ #echo "Serializing parameter $n
"; $temp2[$n] = &XMLRPC_adjustValue; } }else{ $temp2[0] = &XMLRPC_adjustValue; } $temp = $temp2; return $temp; } } function XMLRPC_getMethodName{ #returns the method name return $methodCall['methodCall']['methodName']; } function XMLRPC_request($site, $location, $methodName, $params = NULL, $user_agent = NULL){ $site = explode; if and is_numeric{ $port = $site[1]; }else{ $port = 80; } $site = $site[0]; $data["methodCall"]["methodName"] = $methodName; $param_count = count; if{ $data["methodCall"]["params"] = NULL; }else{ for($n = 0; $nReceived the following parameter list to send:" . XMLRPC_show($params, 'print_r', true)); } $conn = fsockopen ; #open the connection if{ #if the connection was not opened successfully if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "

Connection failed: Couldn't make the connection to $site.

"); } return array(false, array('faultCode'=>10532, 'faultString'=>"Connection failed: Couldn't make the connection to $site.")); }else{ $headers = "POST $location HTTP/1.0rn" . "Host: $sitern" . "Connection: closern" . ($user_agent ? "User-Agent: $user_agentrn" : '') . "Content-Type: text/xmlrn" . "Content-Length: " . strlen . "rnrn"; fputs; fputs; if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "

Sent the following request:

nn" . XMLRPC_show($headers . $data, 'print_r', true)); } #socket_set_blocking ; $response = ""; while{ $response .= fgets; } fclose; #strip headers off of response $data = XML_unserialize(substr($response, strpos($response, "rnrn")+4)); if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "

Received the following response:

nn" . XMLRPC_show($response, 'print_r', true) . "

Which was serialized into the following data:

nn" . XMLRPC_show($data, 'print_r', true)); } if(isset($data['methodResponse']['fault'])){ $return = array(false, XMLRPC_adjustValue($data['methodResponse']['fault']['value'])); if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "nn" . XMLRPC_show($return, 'var_dump', true)); } return $return; }else{ $return = array(true, XMLRPC_adjustValue($data['methodResponse']['params']['param']['value'])); if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "nn" . XMLRPC_show($return, 'var_dump', true)); } return $return; } } } function XMLRPC_response($return_value, $server = NULL){ $data["methodResponse"]["params"]["param"]["value"] = $return_value; $return = XML_serialize; if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_response', "

Received the following data to return:

nn" . XMLRPC_show($return_value, 'print_r', true)); } header; header("Content-Length: " . strlen; header("Content-Type: text/xml"); header; if{ header; } if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_response', "

Sent the following response:

nn" . XMLRPC_show($return, 'print_r', true)); } echo $return; } function XMLRPC_error($faultCode, $faultString, $server = NULL){ $array["methodResponse"]["fault"]["value"]["struct"]["member"] = array(); $temp = $array["methodResponse"]["fault"]["value"]["struct"]["member"]; $temp[0]["name"] = "faultCode"; $temp[0]["value"]["int"] = $faultCode; $temp[1]["name"] = "faultString"; $temp[1]["value"]["string"] = $faultString; $return = XML_serialize; header; header("Content-Length: " . strlen; header("Content-Type: text/xml"); header; if{ header; } if(defined and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_error', "

Sent the following error response:

nn" . XMLRPC_show($return, 'print_r', true)); } echo $return; } function XMLRPC_convert_timestamp_to_iso8601{ #takes a unix timestamp and converts it to iso8601 required by XMLRPC #an example iso8601 datetime is "20010822T03:14:33" return date("YmdTH:i:s", $timestamp); } function XMLRPC_convert_iso8601_to_timestamp{ return strtotime; } function count_numeric_items{ return is_array ? count(array_filter, 'is_numeric')) : 0; } function XMLRPC_debug($function_name, $debug_message){ $GLOBALS['XMLRPC_DEBUG_INFO'][] = array($function_name, $debug_message); } function XMLRPC_debug_print(){ if($GLOBALS['XMLRPC_DEBUG_INFO']){ echo "

n"; foreach($GLOBALS['XMLRPC_DEBUG_INFO'] as $debug){ echo "

$debug[0]

$debug[1]

n"; } echo "

n"; unset($GLOBALS['XMLRPC_DEBUG_INFO']); }else{ echo "

No debugging information available yet.

"; } } function XMLRPC_show($data, $func = "print_r", $return_str = false){ ob_start; $output = ob_get_contents; if{ return "

" . htmlspecialchars . "

n"; }else{ echo "

", htmlspecialchars, "

n"; } } ?>服务端程序例子,server.php 复制代码 代码如下: include 'xml-rpc.inc.php'; //定义可被远程调用的方法 $xmlrpc_methods=array(); $xmlrpc_methods['insertRecords']='insertRecords'; //获得用户传入的方法名和参数 $xmlrpc_request = XMLRPC_parse; $methodName = XMLRPC_getMethodName; $params = XMLRPC_getParams; if (!isset($xmlrpc_methods[$methodName])){ XMLRPC_error; }else { $xmlrpc_methods[$methodName]; } function insertRecords{ if { XMLRPC_error; } XMLRPC_response(XMLRPC_prepare('')); } ?>PHP客户端调用服务端方法例子 复制代码 代码如下:

结果会显示www.emtiit.com

上一篇:"子字符串")用来查找子字符串在母字符串中第一次出现的位置,PHP 碰到结束标记 下一篇:没有了

更多阅读

客户端发送的请求类似这样

编程 2020-02-16
客户端发送的请求类似这样 复制代码 代码如下: $request = array('parameters00','parameters01'); 复制代码...
查看全文

"子字符串")用来查找子字符串在母

编程 2020-02-15
当PHP解析一个文件时,会寻找开始,标记告诉PHP开始和停止解释其中的代码。此种方式的解析...
查看全文

两行前面的dnl

编程 2020-02-15
首先下载最新版vld扩展: 复制代码 代码如下: ~/public_html/php-5.3.13/ext wget ~/public_html/php-5.3.13/e...
查看全文

友情链接: 网站地图

Copyright © 2015-2019 http://www.koi-bumi.com. 韦德体育有限公司 版权所有