I'm on PHP and through a cURL connection I'm receiving SOAP type frames, but I can't find a way to extract the information of interest and then use it.
This is what I receive:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Tue, 12 Feb 2019 16:05:50 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: Multipart/Related; start-info="text/xml"; type="application/xop+xml"; boundary="----=_Part_11693774_xx"
Set-Cookie: TS0133d910=01ca0e1ef6f6e600a5e5f544e580e222d153067bfe4f637ee1fae74f525abcb50681cbd0c3769c51e7a9ab7204cb7a7f2235a061ed; Path=/
Transfer-Encoding: chunked
------=_Part_11693774_xx
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header>
<wsse:security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap-env:mustunderstand="1">
.... DATA....
</wsse:security>
</soap-env:header>
<soap-env:body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="id-11265519">
.... MAS DATA....
</soap-env:body>
</soap-env:envelope>
------=_Part_11693774_xx--
As you can see after the headers there is no typical double line break ( \n\n ) that basically allows me to extract the data and omit the headers, so using str_ireplace I have managed to extract a certain part, but not all :( .
My goal is to extract the data between ------=_Part_11693774_xx and ------=_Part_11693774_xx-- , and then convert it to accessible XML with simplexml_load_string() .
This is what I have coded:
<?php
class Algo{
private $r=NULL;
private $data=NULL;
public function debugResponse() {
$a= str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $this->r);
$b= '<Data>'. $a. '</Data>';
$sxml= simplexml_load_string($b);
print_r($b);
echo "<br><br>Info..<br>";
print_r($sxml);
$this->data= $sxml;
unset($sxml, $a, $b);
}
public function resultado() {
return $this->data;
}
public function exec() {
/* conexion cURL */
$this->r= curl_exec($s);
$this->debugResponse();
}
}
$a= new Algo();
echo 'Datos:<br>'. $a->resultado();
?>
And it returns me:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Tue, 12 Feb 2019 16:05:50 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: Multipart/Related; start-info="text/xml"; type="application/xop+xml"; boundary="----=_Part_11693774_xx"
Set-Cookie: TS0133d910=01ca0e1ef6f6e600a5e5f544e580e222d153067bfe4f637ee1fae74f525abcb50681cbd0c3769c51e7a9ab7204cb7a7f2235a061ed; Path=/
Transfer-Encoding: chunked
------=_Part_11693774_xx
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
<envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<header>
<wsse:security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" mustunderstand="1">
.... DATA....
</wsse:security>
</header>
<body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="id-11265519">
.... MAS DATA....
</body>
</envelope>
------=_Part_11693774_xx--
In this case the last line ------=_Part_11693774_xx-- does not allow me to convert it to XML, because I already did the manual process, remove that last line and now the XML is assembled with the important parts accessible.
---- Edited 02/12/19, 12:49
I have managed to extract the data omitting the headers, but curiously simplexml_oad_string() does not arm the object for me, I leave you the code and result:
<?php
$a= str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $this->r);
$pos= stripos($a, "<envelope");
$pos2= stripos($a, "</envelope>")+strlen('</envelope>');
$b= '<?xml version="1.0" encoding="UTF-8"?><data>'.substr($a, $pos, ($pos2-$pos)).'</data>';
$sxml= simplexml_load_string($b);
print_r($sxml);
?>
And result:
SimpleXMLElement Object
( [Envelope] => SimpleXMLElement Object ( [Header] => SimpleXMLElement Object ( ) [Body] => SimpleXMLElement Object ( ) )
)
Ready, it was resolved, at first I had implemented a function that removed the Signature labels since depending on the SOAP error, it sent me different labels, so the solution found at first was not as effective, but after thinking about it a lot I fell into the need that no label is more useful to me than Body , so I simply proceeded to change the function for this one that I mention and it works great for any type of SOAP with or without Signature received raw by socket.