且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改 SOAP 请求格式

更新时间:2022-04-23 06:09:32

主机公司的 Web 服务存在问题.Web 服务应该接受发送的格式,因为它是正确格式化的 XML.

There is a problem with the host company's web service. The web service should accept the format being sent as it is properly formatted XML.

感谢 Wrikken 的建议,我想出了一个 hacky 解决方案.真正的答案是托管公司修复他们的网络服务以接受格式正确的 XML 请求.

With thanks to Wrikken for his suggestions, I've come up with a hacky solution. The real answer would be for the host company to fix their web service to accept properly formatted XML requests.

我扩展了 SoapClient 类,以便我可以在将 XML 发送到服务器之前对其进行编辑...

I extended the SoapClient class so I could edit the XML before it's sent to the server...

$namespace = 'http://www.???.com/???/';

class HackySoapClient extends SoapClient {

    function __doRequest( $request, $location, $action, $version, $one_way = 0 ) {

        global $namespace;

        // Here we remove the ns1: prefix and remove the xmlns attribute from the XML envelope.
        $request = str_replace( '<ns1:', '<', $request );
        $request = str_replace( '</ns1:', '</', $request );
        $request = str_replace( ' xmlns:ns1="' . $namespace . '"', '', $request );

        // The xmlns attribute must then be added to EVERY function called by this script.
        $request = str_replace( '<Login',           '<Login xmlns="' . $namespace . '"', $request );
        $request = str_replace( '<GetTransactions', '<GetTransactions xmlns="' . $namespace . '"', $request );

        return parent::__doRequest( $request, $location, $action, $version, $one_way = 0 );

    }

}

$soap_client = new HackySoapClient( $wsdl, array(...