更新时间:2023-11-29 23:08:40
我要假设你使用的是WS-I标准的SOAP API V2作为我有这个相同的问题;如果没有,则这可能仍然适用。我从来没有能够连接到V2 API,而它是WS-I标准,这是我发现了这个错误。
I'm going to assume you are using the WS-I compliant SOAP API v2 as I had this exact same issue; if not, then this still might apply. I was never able to connect to the v2 API without it being WS-I compliant, which is how I found this bug.
如果你有看应用程序/ code /核心/法师/原料药/型号/服务器/ WSI /适配器/ Soap.php
文件,你会看到在基本上分成两部分的公共运行功能 - 1为实际的SOAP响应WSDL定义响应和1。
If you have a look at the app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
file you will see in the public run function that is essentially split into two parts - 1 for the WSDL definition response and 1 for the actual SOAP response.
在SOAP响应有一点串替换回事,替换<肥皂:操作的soapAction =>< / SOAP:操作>
的<肥皂:操作的soapAction =/>
等。这显然是导致与内容长度计算的问题 - 这也是发生在WSDL定义响应,但它似乎并没有被引起的问题。
In the SOAP response there is a bit of string replacing going on, substituting <soap:operation soapAction=""></soap:operation>
for <soap:operation soapAction="" />
and so on. This is evidently causing an issue with the content-length calculation - this is also occurring in the WSDL definition response, but it doesn't seem to be causing an issue.
我能够通过更换与下面的code中的尝试大括号中的code成功连接到SOAP API。基本上,我结束了清除头和重新计算的内容长度 在的的字符串替换发生了:
I was able to successfully connect to the SOAP API by replacing the code between the try curly brackets with the code below. Basically, I ended up clearing the headers and recalculating the content-length AFTER the string replacement had taken place:
$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);
希望这有助于