SOAP request with attribute

前端 未结 3 973
渐次进展
渐次进展 2020-12-14 13:02

I can not seem to find out how to set an attribute to a SOAP request without using the XSD_ANYXML encoding.

The request parameter should look as fol

3条回答
  •  温柔的废话
    2020-12-14 13:23

    For this, you need to derived the class from SoapClient and Override the method __doRequest():

    class ABRSoapClient extends SoapClient {
    
        // return xml request
        function __doRequest($request, $location, $action, $version) {
            $dom = new DOMDocument('1.0', 'UTF-8');
            $dom->preserveWhiteSpace = false;
            $xml= $dom->loadXML($request);
            // Goto request Node and Set the attribute
            $attr_ns = $dom->createAttributeNS('xmlns:ns', '' ); // instead of xmlns:ns use Namespace URL
            $attr_ns->value = '/some/ns';
            // add atribute in businessReport node 
            $dom->getElementsByTagName($report_type)->item(0)->appendChild( $attr_ns );   
            $request = $dom->saveXML();
            return parent::__doRequest($request, $location, $action, $version);
        }
    }
    
    $client = new ABRSoapClient(.....);
    $save_result = $client->request($param);
    
    // You can check the form request using function
    $client->__getLastRequest();
    

    I hope this will resolve your problem.

提交回复
热议问题