如何创建这样的肥皂标题:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<requestHeader>
<user>
<userId>ID</userId>
<password>Password</password>
</user>
<service>service</service>
</requestHeader>
如何创建这样的肥皂标题:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<requestHeader>
<user>
<userId>ID</userId>
<password>Password</password>
</user>
<service>service</service>
</requestHeader>
我认为您正在谈论“登录”到 SOAP 服务器所必需的客户端标头,因此基于该假设,这看起来像您想要做的事情:
<?php
$ns = 'urn:namespace'; // the namespace for the request, you don't appear to have any
// actual header construction, based on your structure
$soapHeader = array('user' => array(
'userId' => $__yourUserID,
'password' => $__yourUserPassword,
),
'service' => $__yourService,
);
// Soap Header initialization
$header = new SOAPHeader($ns, 'requestHeader', $soapHeader);
// add the Header to the Soap Client before request
$soap_client->__setSoapHeaders($header);
?>
您需要创建什么并不是很明显,但通常是 PHP DOM 系列函数:
http://php.net/manual/en/book.dom.php
允许生成 XML,将结果保存为字符串以供进一步使用。如果您通过 SOAP 进行通信,或者想要创建一个 SOAP 服务器,那么 PHP SOAP 函数是一个很好的资源: