,所以我正在尝试在PHP中创建一个肥皂客户端/服务器,但是我会遇到以下错误。PS,我知道其他人也问了这个问题并得到了一些答复,我但是,研究了它们,给出的答案没有解决我的错误,这就是我要发布这个问题的原因。
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:xamppphtdocsCprojectclient.php:11 Stack trace: #0 C:xamppphtdocsCprojectclient.php(11): SoapClient->__soapCall('getUsersName', Array) #1 C:xamppphtdocsCprojectservice.php(5): client->getName(Array) #2 {main} thrown in C:xamppphtdocsCprojectclient.php on line 11
这是我的server.php的代码:
<?php
class server
{
private $con;
public function __construct()
{
$this->con=(is_null($this->con)) ? self::connect() : $this->con;
}
static function connect()
{
$con=mysql_connect('localhost','root','root');
$db=mysql_select_db('soap',$con);
return $con;
}
public function getUsersName($id)
{
$id=trim($id['id']);
$sql = "SELECT NAME FROM USERS WHERE ID = '$id'";
$qry = mysql_query($sql, $this->con);
$res = mysql_fetch_array($qry)
return $res['name'];
}
}
$params=array('uri'=>'http://localhost:40/C/project/server.php');
$server= new SoapServer(NULL, $params);
$server->setClass('server');
$server->handle();
?>
这是适用于client.php:
<?php
class client
{
public function __construct()
{
$params=array('location'=>'http://localhost:40/C/project/server.php','uri'=>'urn//localhost:40/cpu6003/project/server.php','trace'=>1);
$this->instance= new SoapClient(NULL,$params);
}
public function getName($id)
{
return $this->instance->__soapCall('getUsersName',$id);
}
}
$client= new client;
?>
最后,服务:
<?php
include './client.php';
$id=array('id' => '1');
echo $client->getName($id);
?>
检查您的服务器日志,server.php可能会丢掉一些错误,它会说出什么问题。
我怀疑这可能是这一行:
$sql = "SELECT NAME FROM USERS WHERE ID = '$id'";
尝试将其更改为这样的东西:
$sql = "SELECT NAME FROM USERS WHERE ID = " . (int)$id;