问题
I override the php SoapClient class in order to add an attribute to the element. When I print the changed code, just before sending, the XML seems to be changed as supposed but when reviewing the XML by __getLastRequest() the XML seems not to have changed at all. In the code I try to add a attribute to the element. Maybe someone knows why the $request_new XML string not send to the server? (OutputXML() is just some nice formating with colering to html)
class SoapClientDebug extends SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
// change / add whatever needed
$request_new = str_replace( '<env:Body', '<env:Body ns1:Id="TheBody"', $request );
// debug out
OutputXML($request_new);
// calling parent
return parent::__doRequest($request_new, $location, $action, $version, $one_way);
}
}
inspected XML outputted before calling parent __doRequest
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://logius.nl/digipoort/koppelvlakservices/1.2/" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://schemas.xmlsoap.org/soap/security/2000-12">
<env:Header>
<ns3:Security env:mustUnderstand="true">
<ns2:Signature>
<ns2:SignedInfo>
<ns2:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ns2:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ns2:Reference>
<ns2:Transforms>
<ns2:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ns2:Transforms>
<ns2:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ns2:DigestValue>$6hpmccmjxQmAI143OhQfIWpkryw=</ns2:DigestValue>
</ns2:Reference>
</ns2:SignedInfo>
<ns2:SignatureValue>sv8n4h0rV4Xmbl+M+w+MLl7lVA8KFsoWRx5DqSKkwSie32jOFoJt0WvH6UWRQI</ns2:SignatureValue>
<ns2:KeyInfo>
<ns2:X509Data>
<ns2:X509IssuerName>CN=TestSignCert</ns2:X509IssuerName>
<ns2:X509SerialNumber>75496503122422458150193540449068096025</ns2:X509SerialNumber>
</ns2:X509Data>
</ns2:KeyInfo>
</ns2:Signature>
</ns3:Security>
</env:Header>
<env:Body ns1:Id="TheBody">
<ns1:aanleverRequest>
<ns1:berichtsoort>Omzetbelasting</ns1:berichtsoort>
<ns1:aanleverkenmerk>Happyflow</ns1:aanleverkenmerk>
<ns1:identiteitBelanghebbende>
<ns1:nummer/>
<ns1:type/>
</ns1:identiteitBelanghebbende>
<ns1:rolBelanghebbende>Intermediair</ns1:rolBelanghebbende>
<ns1:berichtInhoud>
<ns1:mimeType/>
<ns1:bestandsnaam/>
<ns1:inhoud/>
</ns1:berichtInhoud>
<ns1:autorisatieAdres>https://secure.inepd.nl/inloon</ns1:autorisatieAdres>
</ns1:aanleverRequest>
</env:Body>
</env:Envelope>
Reviewing XML by __getLastRequest
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://logius.nl/digipoort/koppelvlakservices/1.2/" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://schemas.xmlsoap.org/soap/security/2000-12">
<env:Header>
<ns3:Security env:mustUnderstand="true">
<ns2:Signature>
<ns2:SignedInfo>
<ns2:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ns2:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ns2:Reference>
<ns2:Transforms>
<ns2:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ns2:Transforms>
<ns2:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<ns2:DigestValue>$6hpmccmjxQmAI143OhQfIWpkryw=</ns2:DigestValue>
</ns2:Reference>
</ns2:SignedInfo>
<ns2:SignatureValue>sv8n4h0rV4Xmbl+M+w+MLl7lVA8KFsoWRx5DqSKkwSie32jOFoJt0WvH6UWRQI</ns2:SignatureValue>
<ns2:KeyInfo>
<ns2:X509Data>
<ns2:X509IssuerName>CN=TestSignCert</ns2:X509IssuerName>
<ns2:X509SerialNumber>75496503122422458150193540449068096025</ns2:X509SerialNumber>
</ns2:X509Data>
</ns2:KeyInfo>
</ns2:Signature>
</ns3:Security>
</env:Header>
<env:Body>
<ns1:aanleverRequest>
<ns1:berichtsoort>Omzetbelasting</ns1:berichtsoort>
<ns1:aanleverkenmerk>Happyflow</ns1:aanleverkenmerk>
<ns1:identiteitBelanghebbende>
<ns1:nummer/>
<ns1:type/>
</ns1:identiteitBelanghebbende>
<ns1:rolBelanghebbende>Intermediair</ns1:rolBelanghebbende>
<ns1:berichtInhoud>
<ns1:mimeType/>
<ns1:bestandsnaam/>
<ns1:inhoud/>
</ns1:berichtInhoud>
<ns1:autorisatieAdres>https://secure.inepd.nl/inloon</ns1:autorisatieAdres>
</ns1:aanleverRequest>
</env:Body>
</env:Envelope>
回答1:
I figured out why, This might be a bit strange to answer my own question but maybe it might help someone in the future; It turned out that __getLastRequest() is not the actual last request in this case. So overriding __doRequest is an option but do not use __getLastRequest in such case!
来源:https://stackoverflow.com/questions/42856124/php-soapclient-override-dorequest-does-not-change-xml-after-str-replace