如果我写错了标题,我很抱歉,我不熟悉SOAP响应及其类型。但我想这是一个WSDL响应,至少我是从WSDL链接获得的......
我有以下网址 http://somedomain.com/j.svc?wsdl
在我使用curl_multi发出请求后,我收到了以下响应。响应缩短为两个结果,因此更容易阅读
回复如下:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetJourneyListResponse xmlns="http://tempuri.org/">
<GetJourneyListResult xmlns:a="http://schemas.datacontract.org/2004/07/DreamFlightWCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Journey>
<a:FromAirport>LHR</a:FromAirport>
<a:TotalPrice>146</a:TotalPrice>
</a:Journey>
<a:Journey>
<a:FromAirport>LHR</a:FromAirport>
<a:TotalPrice>155</a:TotalPrice>
</a:Journey>
</GetJourneyListResult>
</GetJourneyListResponse>
</s:Body>
</s:Envelope>
有没有机会使用PHP解析结果?我做了很多搜索,包括StackOverflow,这里我找到了。
要解析上述响应,我可以使用以下代码:
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('flight','http://schemas.datacontract.org/2004/07/DreamFlightWCF');
foreach ($xml->xpath('//flight:Journey') as $item){
print_r($item);
}
上面的PHP代码片段似乎是部分正确的。我得到了正确数量的“旅程”,但是自己的$项目是空的。
任何解决方案?请不要建议使用SoapClient来检索结果。我无法从curl_multi移动。我已经有了结果,我需要解析它。提前谢谢
答案 0 :(得分:0)
$soap_request = "<?xml version=\"1.0\"?>\n";
$soap_request .= "<soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n";
$soap_request .= " <soap:Body xmlns:m=\"http://www.example.org/stock\">\n";
$soap_request .= " <m:GetStockPrice>\n";
$soap_request .= " <m:StockName>IBM</m:StockName>\n";
$soap_request .= " </m:GetStockPrice>\n";
$soap_request .= " </soap:Body>\n";
$soap_request .= "</soap:Envelope>";
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://ecc6unitst.kaisa.com:8000/sap/bc/srt/wsdl/bndg_386D2B5BD851F337E1000000AC1264E4/wsdl11/allinone/standard/document?sap-client=400" );
curl_setopt($soap_do, CURLOPT_USERPWD, "EBALOBORRP:welcome1");
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$str = curl_exec($soap_do);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
var_dump($str);
print 'Operation completed without any errors';
}
答案 1 :(得分:-1)
首先尝试Parsing SOAP response然后尝试Google。