dongsheng4679 2016-10-06 12:40
浏览 240

PHP通过SOAP传递参数

I am struggling to get to grips with creating the "xml" data for a PHP based SOAP client. I need to produce something like the following:

<SOAP-ENV:Body>
<ns1:check_stock_level>
<ns1:api_credentials>
<ns1:username>*****</ns1:username>
<ns1:password>***</ns1:password>
</ns1:api_credentials>
<productsku>ABC-123</productsku>
</ns1:check_stock_level>
</SOAP-ENV:Body>

I can create the authorisation section, but my code fails to create the productsku - the code looks like this:

$client = new SoapClient("https://www.example.net/wh_api.asmx?WSDL",array("trace"=> 1, "exceptions" => 0));
$auth = array ('api_credentials' => array ('username'=>'******', 'password'=>'******'));
$sku = array('productsku'=>'ABC-123');
$result = $client->check_stock_level($auth, $sku);

which produces this:

<SOAP-ENV:Body>
<ns1:check_stock_level>
<ns1:api_credentials>
<ns1:username>*****</ns1:username>
<ns1:password>***</ns1:password>
</ns1:api_credentials>
</ns1:check_stock_level>
<param1>
<item>
<key>product_sku</key>
<value>ABC-123</value>
</item>
</param1>
</SOAP-ENV:Body>

Where the productsku is outside of the <check_stock_level> tag set and is surrounded by extra tags.

Most examples I can find on SOAP use NuSOAP but I want to use the native pHP SOAP functionality. Can anyone give me any pointers?

  • 写回答

1条回答 默认 最新

  • doutan2228 2016-10-09 17:56
    关注

    Resolved it myself, the two arrays needed to be combined - by having them as separate arrays, the productsku data was moved outside of the tag set.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大