我假设您正在使用符合 WS-I 的 SOAP API v2,因为我遇到了完全相同的问题;如果不是,那么这仍然可能适用。如果 v2 API 不符合 WS-I 标准,我就无法连接到它,这就是我发现这个 bug 的原因。
如果你看一下app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
您将在公共运行函数中看到该文件,该函数本质上分为两部分 - 1 个用于 WSDL 定义响应,1 个用于实际 SOAP 响应。
在 SOAP 响应中,有一些字符串替换正在进行,替换<soap:operation soapAction=""></soap:operation>
for <soap:operation soapAction="" />
等等。这显然导致了内容长度计算的问题 - 这也发生在 WSDL 定义响应中,但它似乎并没有导致问题。
通过将 try 大括号之间的代码替换为下面的代码,我能够成功连接到 SOAP API。基本上,我最终清除了标题并重新计算内容长度AFTER字符串替换已经发生:
$this->_instantiateServer();
$content = preg_replace(
'/(\>\<)/i',
">\n<",
str_replace(
'<soap:operation soapAction=""></soap:operation>',
"<soap:operation soapAction=\"\" />\n",
str_replace(
'<soap:body use="literal"></soap:body>',
"<soap:body use=\"literal\" />\n",
preg_replace(
'/<\?xml version="([^\"]+)"([^\>]+)>/i',
'<?xml version="$1" encoding="'.$apiConfigCharset.'"?>',
$this->_soap->handle()
)
)
)
);
$this->getController()->getResponse()
->clearHeaders()
->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
->setHeader('Content-Length',strlen($content))
->setBody($content);
希望这可以帮助