PHP SoapClient请求XML生成多余<ns2:id>节点的问题求助
PHP SoapClient请求XML生成多余ns2:id节点的问题求助
我最近在用PHP的SoapClient调用爱立信的CAI3G1.2接口时卡壳了,生成的请求XML里多了个服务器完全不接受的<ns2:id>子节点,想请各位大佬帮忙看看怎么调整代码才能生成正确的XML结构。
问题核心
我需要构造的rule节点只需要带id属性即可,但SoapClient生成的XML里,除了<ns2:rule id="999">这个属性,还凭空多了个<ns2:id>999</ns2:id>子节点,服务器直接拒绝了这个请求。而用SoapUI构造的纯属性版请求(没有多余子节点)就能正常被服务器接受。
我的代码片段
简化后的参数数组
$params = array ( 'communication' => [ 'user-configuration' => [ 'ruleset' => [ 'rule' => [ '_' => '', 'id' => '999', 'conditions' => [ 'rule1' => 'true', ], 'actions' => [ 'forward-to' => [ 'target' => '123456' ], ], ], ], ], ], );
SoapClient初始化与接口调用代码
$client = new SoapClient ($wsdl, array( 'location' => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2", 'uri' => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2", 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'connection_timeout' => 5, 'trace' => 1, 'encoding'=>'UTF-8' )); $header = new SoapHeader('http://schemas.ericsson.com/cai3g1.2/','SessionId',$sessionID,false); $client->__setSoapHeaders($header); try { $response = $client->Set($params); } catch(Exception $e){ if ($debug) print_r($e); return $e; } return $response;
生成的问题XML(多余节点已标注)
<ns2:communication> <ns2:user-configuration> <ns2:ruleset> <ns2:rule id="999"> <!-- 下面这个是服务器不接受的多余节点 --> <ns2:id>999</ns2:id> <ns2:conditions> <ns2:rule1>true</ns2:rule1> </ns2:conditions> <ns2:actions> <ns2:forward-to> <ns2:target>123456</ns2:target> </ns2:forward-to> </ns2:actions> </ns2:rule> </ns2:ruleset> </ns2:user-configuration> </ns2:communication>
服务器能接受的正确XML(SoapUI生成):
<ns2:communication> <ns2:user-configuration> <ns2:ruleset> <ns2:rule id="999"> <ns2:conditions> <ns2:rule1>true</ns2:rule1> </ns2:conditions> <ns2:actions> <ns2:forward-to> <ns2:target>123456</ns2:target> </ns2:forward-to> </ns2:actions> </ns2:rule> </ns2:ruleset> </ns2:user-configuration> </ns2:communication>
我尝试过的无效方法
我还试过先写好正确的XML字符串,再用simplexml_load_string转成数组作为参数,代码如下:
$xml_string= '<communication> <user-configuration> <ruleset> <rule id="999"> <conditions> <rule1>true</rule1> </conditions> <actions> <forward-to> <target>123456</target> </forward-to> </actions> </rule> </ruleset> </user-configuration> </communication>'; $xml_array = simplexml_load_string($xml_string);
但结果更糟——请求里连<rule>部分都直接消失了,完全不符合预期。
真心希望有经验的朋友能指点下,到底该怎么构造参数或者调整SoapClient的配置,才能生成正确的XML结构呢?
内容来源于stack exchange
相关产品推荐
相关产品推荐

