使用 PHP SOAPclient 将键值 XML 转换为其他格式?
Transform key-value XML into other format with PHP SOAPclient?
我想将我的 SOAP 请求从键值格式转换为另一种格式:
<SOAP-ENV:Header>
<ns2:AUTH>
<item>
<key>username</key>
<value>testuser</value>
</item>
<item>
<key>password</key>
<value>xxxxx</value>
</item>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这就是我想要的:
<SOAP-ENV:Header>
<ns2:AUTH>
<username>testuser</username>
<password>xxxxx</password>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig>
<partner_id>1</partner_id>
</ns1:getProductConfig>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我的 PHP 代码,我在其中创建了一个新的 SoapClient 对象:
$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;
PS: 目前,它是非 wsdl 风格,但我正在考虑更改为也使用 wsdl。
这听起来很疯狂,但我只是改用 WSDL 解决了这个问题。
容易多了。 WSDL 文件将确定 SOAP 请求和响应。
我想将我的 SOAP 请求从键值格式转换为另一种格式:
<SOAP-ENV:Header>
<ns2:AUTH>
<item>
<key>username</key>
<value>testuser</value>
</item>
<item>
<key>password</key>
<value>xxxxx</value>
</item>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这就是我想要的:
<SOAP-ENV:Header>
<ns2:AUTH>
<username>testuser</username>
<password>xxxxx</password>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig>
<partner_id>1</partner_id>
</ns1:getProductConfig>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我的 PHP 代码,我在其中创建了一个新的 SoapClient 对象:
$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;
PS: 目前,它是非 wsdl 风格,但我正在考虑更改为也使用 wsdl。
这听起来很疯狂,但我只是改用 WSDL 解决了这个问题。
容易多了。 WSDL 文件将确定 SOAP 请求和响应。