I'm working on a custom shipping method linked with an external REST API.

When the seller submits a shipment, an API call is done in order to reserve a shipping course for our carriers.

The problem is that the cURL call fails with this error:

cURL Error: name lookup timed out

I tried something like this :

$curlPostData = $bookCourseRequest; // an object containing the data sent to the API

$curlQuery = curl_init( //we will assume that the URL is correct );
curl_setopt($curlQuery, CURLOPT_POST, true);
curl_setopt($curlQuery, CURLOPT_POSTFIELDS, $curlPostData);
$header = array("content-type: application/json");
curl_setopt($curlQuery, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlQuery, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlQuery, CURLOPT_CONNECTTIMEOUT, 30);
$curlAnswer = curl_exec($curlQuery);
if (!$curlAnswer)
    mage::log("cURL Error: " . curl_error($curlQuery));
    $answer = json_decode($curlAnswer);

Fun fact: this code works well on Magento 2 and on an PHP file unlinked with Magento. With Magento 1.9, there is a timeout error.

I tried the varian way but no luck: still the same error.

Does someone knows how to solve it?


Please check below code


$client_account_details = new Zend_Http_Client('https://domain.com/');
        $client_account_details->setHeaders('X-Auth-Token','token' );
        $client_account_details->setHeaders('Content-Type', 'application/json');  

Post :-

$request_json = json_encode($response_array);
    $client = new Zend_Http_Client();   
    $client->setHeaders('X-Auth-Token','token' );
    $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json'); 
    $response = $client->request()->getBody();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.