我正在使用PHP SoapClient()来使用Web服务。
$sc = new SoapClient($uri);
$sc->MyAction($params);
$ params将是一个用于在下面创建XML的数组,但我不确定如何格式化有多个OrderLine键的数组。
<args>
<OrderLines>
<OrderLine>
<LineNumber>1</LineNumber>
<Product>Acme Foos</Product>
<Description>Bars and Bazzes</Description>
<Quantity>1</Quantity>
<Price>5.00</Price>
</OrderLine>
<OrderLine>
<LineNumber>2</LineNumber>
<Product>Kittens</Product>
<Description>Very sleepy</Description>
<Quantity>1</Quantity>
<Price>12.00</Price>
</OrderLine>
</OrderLines>
</args>
这是我发送的数组格式的转储,但未成功,因为我不确定如何使用多个 OrderLine 键创建数组。
[args] => Array
(
[OrderLines] => Array
(
[0] => Array
(
[LineNumber] => 1
[Product] => 'Acme Foos'
[Description] => 'Bars and Bazzes'
[Quantity] => 1
[Price] => 5.00
)
[1] => Array
(
[LineNumber] => 2
[Product] => 'Kittens'
[Description] => 'Very sleepy'
[Quantity] => 1
[Price] => 12.00
)
)
)
将此信息发送到Web服务时,我收到以下SoapFault异常:
服务器无法读取请求。 ---&GT; XML中存在错误 文件(2,1001)。 ---&GT;输入字符串的格式不正确。
答案 0 :(得分:0)
这个例子是正确的。该错误与数组无关。这是我的参数中的一些其他无效数据。