Question

I am getting "Error Fetching http body, No Content-Length, connection closed or chunked data" when doing a SOAP request to the Fedex Rate service.

Running Apache 2.4.4, PHP 5.4.12. This code is working on a different server, which is running Apache 2.2.3, PHP 5.3.27.

Here is my PHP code:

require_once('fedex-common.php5');
$path_to_wsdl = __DIR__ . "/RateService_v10.wsdl";
ini_set( "soap.wsdl_cache_enabled", "0" );

$context = stream_context_create(array(
    'http'=>array(
        'protocol_version' => 1.0
    )
));

$client = new SoapClient( $path_to_wsdl, array( 'trace' => 1,  'stream_context'=>$context ) ); 

...

try {
    ...
    $response = $client->getRates( $request );
    ...
} catch ( SoapFault $exception ) {
    echo($client->__getLastRequestHeaders());
    echo($client->__getLastResponseHeaders());
    printFault( $exception, $client );
}

Running the code gives the following headers in the catch block - Request:

POST /web-services/rate HTTP/1.1
Host: ws.fedex.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.4.12
Content-Type: text/xml; charset=utf-8
SOAPAction: "getRates"
Content-Length: 3875

Response:

HTTP/1.1 200 OK
Date: Thu, 31 Oct 2013 19:12:23 GMT
Server: Apache/2.2
x-wily-servlet: Encrypt1 GaMcoOotgOSMyoYj73M4dqm654IQUUy2VYo7kRLnWqp7O1G9YaZThSMVcxtIAA7cQSSESAO/CtqxI1OyaPemJzOZK7N+WNRwu686y5jWfxAuKqFeRiYJ1NPQTJShYPzp7gOpypOE/sg3Ti/CjdT3XaNt6/pEd18+pXDMyIfKrxnz4xWyAOl9y4Rosae418ks0PYNS9GJy2iOfaSXRiWFkA==
X-Powered-By: Servlet/2.5 JSP/2.1
x-wily-info: Clear guid=0FEE460DCC8738E20EC18F87798CDA26
Vary: Accept-Encoding
Keep-Alive: timeout=8, max=1024
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/xml; charset=utf-8

I am confused that the request is being made with HTTP/1.1 when I specify HTTP/1.0 (per recommendations on other questions). Also in the response header, it's definitely returning chunked data, causing that error. When I run the request myself in Advanced REST client (chrome extension), it works correctly, but also includes the Transfer-Encoding: chunked header that I believe is causing the problem.

I suspect there is some kind of issue with my Apache or PHP configuration.

Solution: Downgrading to Apache 2.2.22 and PHP 5.3.13 fixed the issue

Was it helpful?

Solution

Downgrading to Apache 2.2.22 and PHP 5.3.13 fixed the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top