[英]PHP - SOAP API authentication
I encounter some problems when I try to call a method of api with authentication.当我尝试通过身份验证调用 api 的方法时遇到一些问题。
$auth = (object) array(
'user'=>'username',
'password'=>'password',
'company'=> 'companyname'
);
$url = 'https://webservices.gocadservices.com/NVS?wsdl';
$soap = new SoapClient('https://webservices.gocadservices.com/NVS?wsdl',$auth);
echo $soap->nop();
I get an error: The user parameter is empty or missing.我收到一个错误:用户参数为空或丢失。
My question: How can I send a request xml like this:我的问题:我怎样才能像这样发送请求 xml :
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<xs:nvheader xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:nvcommand>
<xs:user>
username
</xs:user>
<xs:password>
mot de passe
</xs:password>
<xs:company>
companyname
</xs:company>
</xs:nvcommand>
</xs:nvheader>
</soapenv:Header>
</soapenv:Envelope>
I must have this structure so that the API SOAP will work.我必须有这个结构,这样 API SOAP 才能工作。 Thanks.谢谢。
You need to set a SOAP Header for this to work:您需要设置 SOAP Header 才能使其工作:
$nvcommand = (object)[
'user' => 'username',
'password' => 'password',
'company' => 'company'];
$authHeader = new SoapHeader('namespace','nvcommand', $nvcommand);
$soapClient = new SoapClient('http://localhost:44333/SoapService.com?wsdl', $soapOptions);
$soapClient->__setSoapHeaders($authHeader);
$return = $soapClient->__soapCall('HelloWorld',[]);
This will send a SOAP Header这将发送一个 SOAP Header
<env:Header>
<ns2:nvcommand>
<user>username</user>
<password>password</password>
<company>company</company>
</ns2:nvcommand>
</env:Header>
along with the Request.连同请求。 The options array in the SoapClient ctor isnt used to pass auth information. SoapClient ctor 中的选项数组不用于传递身份验证信息。 Please refer to https://www.php.net/manual/de/soapclient.construct.php请参考https://www.php.net/manual/de/soapclient.construct.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.