0
我使用在PHP捲曲發送SOAP請求但響應被返回作爲字符串時我的var_dump的響應,並且我不能它解析成XML如何使用curl在php中讀取和解析來自SOAP請求的XML響應?
$soapUrl = "https://hosting/Wsdl"; // asmx URL of WSDL
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<MY DATA>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Host: hosting,
"Connection: Keep-Alive",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-type: text/xml;charset=\"utf-8\"",
"SOAPAction: http://hosting.com/SOAPAction",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
var_dump($response);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response);
echo '<pre>';
var_dump($parser);
echo '</pre>';
響應返回作爲
string(9965) "RESPONSE DATA"
object(SimpleXMLElement)#164 (0) { }
請提前幫助和多謝。
你好,但它不是返回標記名。你可以讓知道如何獲取標記名 – androidBeckhamania