我无法使用PHP SoapClient访问第三方SOAP服务。
该服务需要基本身份验证,尽管提供了用户名和密码,但我始终会收到“需要授权”异常。
我尝试了其他类似线程的许多建议,但没有帮助。 nusoap库造成大量内存泄漏,即使PHP允许有1 GB内存也无法应付调用。
下面是我用来测试服务的类。
class SoapCallService
{
private $username = 'xxx';
private $password = 'yyy';
public function checkCPRNumber($cprNumber)
{
try {
$opts = array(
'http' => array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$soapClientOptions = array(
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE,
'login' => $this->username,
'username' => $this->username,
'password' => $this->password,
'location' => "http://zzz.zz",
'trace' => 1
);
$client = new SoapClient($this->getWSDL(), $soapClientOptions);
$request = [
'PersonInformation' => [
"PersonCPRNumber" => $cprNumber,
],
'Kontekst' => [
]
];
var_dump($client->__getFunctions());
$result = $client->__soapCall('CSRPValidation', [$request]);
print_r($result);
print "<p>Request :" . htmlspecialchars($client->__getLastRequest()) . "</p>";
print "<p>Response:" . htmlspecialchars($client->__getLastResponse()) . "</p>";
} catch (\Exception $e) {
echo $e->getMessage();
}
}
private function getWSDL()
{
return '/path/to/local/Service.wsdl';
}
}