我在这2天里苦苦挣扎,几乎尝试了我在互联网上发现的一切。我在头文件securityContext中有用户名和密码的SOAP服务,但不知道如何在PHP中以该形式提供数据?
这是必需的标题XML:
<soap:Header>
<SecurityContext xmlns="http://tempuri.org/">
<userName>string</userName>
<password>string</password>
</SecurityContext>
</soap:Header>
答案 0 :(得分:0)
添加标题值的部分:
$soap = new SoapClient($wsdl, $options);
$auth = array(
'userName' => self::SOAP_USERNAME,
'password' => self::SOAP_PASSWORD,
);
$header = new SoapHeader(self::SOAP_NAMESPACE, 'SecurityContext', $auth);
$soap->__setSoapHeaders($header);
另外,因为它的https请求我需要添加一些ssl选项:
// set stream context opts
$opts = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
// set options
$options = array(
'encoding' => 'UTF-8',
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'connection_timeout' => 15,
'login' => self::SOAP_USERNAME,
'password' => self::SOAP_PASSWORD,
'stream_context' => stream_context_create($opts),
);