Я использую приведенный ниже код для запроса SOAP.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://example.com?WSDL",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://Xyz.Abc\" xmlns:ns2=\"http://tempuri.org/\"><SOAP-ENV:Body><ns2:GetStatus><ns1:ReferenceNo>12345</ns1:ReferenceNo></ns2:GetStatus></SOAP-ENV:Body></SOAP-ENV:Envelope>",
CURLOPT_HTTPHEADER => array(
"Content-Type: text/xml"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Ответ: Получение ответа ниже, когда я задаю header('Content-type: application/xml');
в php сценарии, который является правильным.
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>...</env:Header>
<env:Body>
<GetStatusResponse xmlns:s1="http://Xyz.Abc" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns="http://tempuri.org/">
<s1:StatusResponse>
<s1:Test ResponseCode="INPROGRESS" ResponseMessage="Reference no. 12345"/>
</s1:StatusResponse>
</GetStatusResponse>
</env:Body>
</env:Envelope>
Как извлечь значения тела из ответа, не печатая в браузере?
Вот что я пытался
Удалить заголовок xml и проанализировать строку ответа с помощью simplexml_load_string
method.
$xml = simplexml_load_string($response);
echo $xml;
$json = json_encode($response);
$arr = json_decode($json,true);
print_r($arr);
Я также пытался с SimpleXMLElement
, но он печатает пустой ответ:
$test = new SimpleXMLElement($response);
echo $test;
Но он печатает пустой результат.