NuSOAP 库中似乎有一点遗漏...它假定内容标头必须是“text/xml”,因此如果您的客户端尝试连接到输出应用程序/soap+xml 标头的服务,您最终会遇到如下错误:
不是文本/xml类型的响应:application/soap+xml;字符集=utf-8
要对此进行测试,您可能会受益于以下我用来登录 SOAP 服务的小函数模式。请记住,打印出客户端对象!您实际上可能看不到结果!
require_once('path/to/downloaded/libraries/nusoap.php');
var $endpoint = 'https://somedomain.com/path/to/soap/server/Login';
var $client; // the soapclient object
function SOAP_Login()
{
$this->client = new soapclient($this->endpoint);
$err = $this->client->getError();
if ($err)
{
// Display the error
echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
exit;
// At this point, you know the call that follows will fail
}
$params = array(
'some' => 'thing.. depends on what the WSDL expects'
);
$result = $this->client->call('someFunction', $params);
print_r($result); // Without the fix, this prints nothing (i.e. false) !!!
print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str
}
当我打印 $result 时,我什么也没得到,但是当我打印 $client 对象时,我可以看到有错误。
我实现的小技巧是在 nusoap.php 文件中,大约第 7500 行。寻找这个 if 语句:
if (!strstr($headers['content-type'], 'text/xml')) {
$this->setError('Response not of type text/xml: ' . $headers['content-type']);
return false;
}
把它改成这样:
if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) {
$this->setError('Response not of type text/xml: ' . $headers['content-type']);
return false;
}
这一切只是让 NuSOAP 处理发出“application/soap+xml”标头(这是一个有效的 xml 标头)的响应。