PHP SOAP client that understands multi-part messages?

后端 未结 7 594
死守一世寂寞
死守一世寂寞 2020-12-03 03:27

Is there such a beastie? The simple SOAP client that ships with PHP does not understand multi-part messages. Thanks in advance.

7条回答
  •  無奈伤痛
    2020-12-03 04:21

    A little bit more simple IMHO

    class SoapClientUnwrappedXml extends SoapClient
    {
    
        const SOAP_ENVELOPE_REGEXP = '/^]*>(.*)<\/soap:Envelope>/m';
    
        /**
         * Sends SOAP request using a predefined XML.
         *
         * Overwrites the default method SoapClient::__doRequest() to make it work
         * with multipart responses or prefixed/suffixed by uuids.
         *
         * @return string The XML Valid SOAP response.
         */
        public function __doRequest($request, $location, $action, $version, $one_way = 0): string
        {
            $result = parent::__doRequest($request, $location, $action, $version, $one_way);
            $headers = $this->__getLastResponseHeaders();
    
            if (preg_match('#^Content-Type:.*multipart\/.*#mi', $headers) !== 0) {
                preg_match_all(self::SOAP_ENVELOPE_REGEXP, $result, $resultSanitized, PREG_SET_ORDER, 0);
                $result = $resultSanitized[0][0] ?? $result;
            }
    
            return $result;
        }
    }
    

提交回复
热议问题