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 $curlPostData = json_encode($curlPostData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $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)); else $answer = json_decode($curlAnswer); curl_close($curlQuery);
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?