PHP SoapClient中SOAP响应的开头和结尾附加的不需要的字符串

Ash*_*del 8 php xml soap web-services

我在尝试从SOAP API服务器获取请求时执行以下php代码

try {
    $soap = new SoapClient($wsdl, $options);
    $data = $soap->GetXYZ($params);
}
catch(Exception $e) {
    $Lastresponse = $soap->__getLastResponse();
}
Run Code Online (Sandbox Code Playgroud)

我得到的只是"看起来我们没有XML文档"的响应代码.

但是当我查看catch块中的$ Lastresponse变量时,我发现它如下:

------=_Part_1134075_393252946.1482317378966 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/> <SOAP-ENV:Body> ......all valid data ... </SOAP-ENV:Body> </SOAP-ENV:Envelope> ------=_Part_1134075_393252946.1482317378966--

注意:我使用的$ options参数是:

$options = array(
    'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
    //'style'=>SOAP_RPC,
    //'use'=>SOAP_ENCODED,
    'soap_version'=>SOAP_1_1,
    'cache_wsdl'=>WSDL_CACHE_NONE,
    'connection_timeout'=>15,
    'trace'=>true,
    'encoding'=>'UTF-8',
    'exceptions'=>true
);
Run Code Online (Sandbox Code Playgroud)

虽然我做了一个解析xml的解决方法,但有没有人对这些额外的-----部分位有任何想法?有什么我做错了吗?

Rei*_*Rei 5

这些  -----Part 东西在此处解释并在RFC2387中定义的多部分消息中称为边界.

经过调查,似乎SoapClient无法解析多部分消息,这就是您获得该异常的原因.

解决方案是扩展SoapClient以使用正则表达式或其他字符串函数提取XML内容.以下是此页面中的示例:

class MySoapClient extends SoapClient {
    public function __doRequest($request, $location, $action, $version, $one_way = 0) { 
        $response = parent::__doRequest($request, $location, $action, $version, $one_way);
        $start = strpos($response,'<?xml'); 
        $end = strrpos($response,'>'); 
        return substr($response,$start,$end-$start+1);
    }
}
Run Code Online (Sandbox Code Playgroud)