PHP SOAP调用中多个具有相同名称的元素 [英] Multiple elements of same name in PHP SOAP Call

查看:74
本文介绍了PHP SOAP调用中多个具有相同名称的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这类问题已经问过很多次了。我花了几个小时阅读并尝试提供的解决方案-但似乎没有一种适合我的情况。

I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.

我需要将SOAP请求发送到可以包含API的API这样重复的元素:

I need to send a SOAP request to an API that can contain an element that repeats like so:

<operationNumbers>
    <operationNumber>1234</operationNumber>
    <operationNumber>1235</operationNumber>
    <operationNumber>1236</operationNumber>
    <operationNumber>1237</operationNumber>
</operationNumbers>

我确实读过,也许我可以这样做:

I did read that perhaps I could do this:

  $buildRequest = Array(
      'myheader' => Array(
      'date' => MY_DATE,
      'id' => Array(
          'client' => CLIENT,
          'clientRef' => MYREF
          )
      ),
      'operationNumbers' => Array (
          Array('operationNumber' => '1234'),
          Array('operationNumber' => '1235')
      )
   ); 

   $request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );

不幸的是,如果我发送一个操作号,这将无法正常工作并导致请求无效例如:

Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:

 ...
  'operationNumbers' => Array (
      'operationNumber' => '1234'
   )
 ...

请求成功。我已经尝试过soapVars / soapParams,但是无法使用这种方法正常工作。

The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.

推荐答案

所以,我解决了。

 $operationNumbersArray = array('1234','1235');

 ...

       'operationNumbers' => array(
           'operationNumber' => $operationNumbersArray
        )

测试和摆弄,我无意中删除了另一个强制性的值。该API未给出警告(忽略)。

During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).

这篇关于PHP SOAP调用中多个具有相同名称的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆