Magento - 在 Lion 下使用 MAMP 堆栈时 SOAP API 响应不完整
我使用soapUI 测试了Magento 的SOAP API。我成功登录并获得了登录哈希。 然后我尝试检索产品列表,效果很好。
这是在使用最新版本的 Apache、mySQL 和 PHP 的 Linux 服务器上进行的。
然后我创建了 Magento 和数据库的备份。我想使用 MAMP 堆栈在 Lion 服务器上创建一个测试环境。 Magento 备份似乎工作正常,但 SOAP API 却不行。
我再次使用soapUI 来获取登录哈希并尝试检索所有产品。但现在响应似乎不完整:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:catalogProductListResponseParam>
<result>
<complexObjectArray>
<product_id>7167</product_id>
<sku>000140</sku>
... etc ...
<complexObjectArray>34</complexObjectArray>
</category_ids>
<website_ids>
<complexObjectArray>1</complexObjectArray>
</website_ids>
</complexObjectArray>
<complexObjectArray>
<product
为什么在Lion/MAMP下响应不完整?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经遇到过 SOAP XML 响应不完整的问题。
设置如下所示:
即使您使用不同的 Magento 版本和不同的 SOAP 调用,您也可以可能会遇到像我一样的错误。问题是响应的 HTTP Content-Length 标头计算不正确 > 8000 字节。
如何验证您是否受到此错误的影响:
由于第二种方法是更准确的方法,所以我会采用这种方法。
将搜索/替换操作的结果写入变量并记录下来以供进一步检查。代码可能如下所示:
执行 SOAP API 调用并在 Magento 目录中打开 var/log/soap.log。如果日志文件中的 XML 完整,但响应中不完整,则 Content-Length 标头就是问题所在。
如何更正 Content-Length 标头
保留 Mage_Api_Model_Server_Wsi_Adapter_Soap 副本并向我们刚刚修改的代码添加一行:
注意这一行:
我们计算并设置 Content-Length 标头。第三个参数 true 很重要,因为它告诉框架覆盖现有的 Content-Length 标头。
如果您问为什么会出现此问题,我无法准确告诉您,因为我没有一路追查该错误。
据我所知,只要 XML 响应的长度 <= 8000 字节,一切都很好。如果响应长度超过 8000 字节且 XML 由 x 行组成,则响应将被截断 x 个字符。看起来这是不同的回车代码和/或编码问题的问题,导致响应内容长度的计算错误。
I had a problem with incomplete SOAP XML responses once.
The setup was like this:
Even if you use a different Magento version and a different SOAP call, you may suffer from a similar bug as I did. The problem was that the HTTP Content-Length header was calculated incorrectly for responses > 8000 bytes.
How to verify if you are affected by this bug:
As the second way is the more accurate way to do it, I'll go with this.
Write the result of the search/replace operations into a variable and log it for further examination. The code may look like this:
Execute the SOAP API call and open var/log/soap.log in your Magento directory. If the XML is complete in the log file but not in your response, then the Content-Length header is the problem.
How to correct the Content-Length header
Stay in your copy of Mage_Api_Model_Server_Wsi_Adapter_Soap and add one line to the code we just modified:
Note the line:
We calculate and set the Content-Length header. The third parameter, true, is important because it tells the framework to overwrite the existing Content-Length header.
If you ask why this problem occurs I can't tell you exactly because I didn't hunt the bug all the way down.
From what I saw, everything is fine as long as the XML response has a length <= 8000 bytes. If the response is longer than 8000 bytes and the XML consists of x lines, the response is truncated by x characters. It looks like it is a problem with the different carriage return codes and/or with encoding issues which lead to the wrong calculation of the response content length.
我认为您的 PHP 配置发生了变化。您可能会遇到 PHP.ini
memory_limit
或max_execution_time
错误。您应该能够通过在 Magento 根目录中的每个服务器上创建一个简单的文件(将文件放入 Magento 根目录中很重要,因为 .htaccess 文件可能会覆盖 PHP 设置)并比较值来比较 PHP 设置: >info.php
您还可以检查 Apache 错误日志以获取更多信息。
I think that your PHP configuration changed. You're likely running into a PHP.ini
memory_limit
ormax_execution_time
error. You should be able to compare your PHP settings by creating a simple file on each server in your Magento root (it's important that you put the file in your Magento root because the .htaccess file might be overriding PHP settings) and comparing values:info.php
You can also check your Apache error logs for additional information.