我想使用php webservice中的nusoap将数据作为xml从客户端发送到服务器。我可以将它作为一个数组发送。这是我的代码。
客户端
<?php
$name='admin';
$pass='admin';
if(isset($_POST['submit'])){
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost/web_service/server.php?wsdl', true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $client->call('login', array('name' => $name,'pass'=>$pass));
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
}
?>
服务器
<?php
require_once('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('server', 'urn:server');
$server->register('login',
array('name' => 'xsd:string','pass'=>'xsd:string'),
array('return' => 'xsd:string'),
'urn:server',
'urn:server#login',
'rpc',
'encoded',
'Login Authentication'
);
function login($name,$pass) {
if($name && $pass == 'admin'){
return 'Welcome, ' . $name;
}
else{
return '<h2>Oops,</h2> looks like something went wrong. Please try again';
}
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
我希望发送变量$ name&amp; $作为xml传递给服务器,需要服务器解析xml并获取值。这可能。