DHL Not Working with Production API URL in Magento 1.7 – Fix Guide

dhlmagento-1.7

I'm stuck on this issue with DHL on Magento 1.7.1 :

Symptoms:

Details:

  • DHL response is empty
  • an exception is trigger by and cached in Zend_Http_Response(579) and then caught in Mage_Usa_Model_Shipping_Carrier_Dhl_International(849):
    Error parsing body – doesn't seem to be a chunked message

I contacted DHL but they say everything is correct on their side.

Any one is experiencing same problem ? what I should check ?

Thanks you in advance

Best Answer

As for question description this is a problem related to Magento < 1.8 and the fix is contained in this class Varien_Http_Adapter_Curl

Solution:

Just copy this filelib/Varien/Http/Adapter/Curl.php from Magento 1.8.1 in app/code/local/Varien/Http/Adapter/Curl.php

Details:

Debugging Zend/Http/Reponse.php (Zend_Http_Response) and the response Header, I have found out that there is a difference in the processed response.

Response Header for on 1.8.1

HTTP/1.1 200 OK
Date: Tue, 22 Apr 2014 18:02:54 GMT
Content-Type: text/xml
X-Powered-By: Servlet/2.4 JSP/2.0
Set-Cookie: BIGipServerxmlpi-ea=705054885.47394.0000; expires=Tue, 22-Apr-2014 18:27:55 GMT; path=/
Via: 1.1 xmlpi-ea.dhl.com
Connection: close
Set-Cookie: TSfc8311=659c38c63b540f107d6b7aef1bc64ce8ee76bc99a82a71c35356aecf8b05127e488cf5af; Path=/; Secure; HTTPOnly

Response Header for on 1.7.0.2

HTTP/1.1 200 OK
Date: Tue, 22 Apr 2014 18:04:25 GMT
Content-Type: text/xml
X-Powered-By: Servlet/2.4 JSP/2.0
Set-Cookie: BIGipServerxmlpi-ea=721832101.51273.0000; expires=Tue, 22-Apr-2014 18:29:26 GMT; path=/
Via: 1.1 xmlpi-ea.dhl.com
Connection: close
Set-Cookie: TSfc8311=da50e84622b1ff8f8df2403bc7a21df3a051ef21157ed05c5356af2a8b05127e528e9abf; Path=/; Secure; HTTPOnly
Transfer-Encoding: chunked

The main difference here is the presence of Transfer-Encoding: chunked.
This is causing Zend_Http_Response to use decodeChunkedBody() method that finally trigger an exception:
-- Error parsing body - doesn't seem to be a chunked message

Now it is not clear to me if this is bug in Zend/Varien because it looks more a bug in the DHL response. ( if we use DHL Test API URL the response doesn't contains the guilty header entry )

If you look read() method in Varien_Http_Adapter_Curl ( that is the only changed method in respect to Magento 1.7.1 version ) you will see Varien team has workarounded the issue just cleaning the header form that entry.

Related Topic