0

I have a trouble .From HunterExpress API, I want to fetch freight charge amount for that passing postCode,product dimensions/weight etc I am using the following code to fetch freight charge

$data = array(
    'username' => "xxx",
    'password' => "xxx",
    'customerCode' => "DUMMY",
    'fromLocation' => array( "suburbName"=> "MELBOURNE", "postCode"=> "3000", "state"=> "VIC"),
    'toLocation' =>array( "suburbName"=> "SYDNEY", "postCode"=> "2000", "state"=> "NSW"),
    'goods' =>array( "pieces"=> "2",
    'weight' => "3",
    'width' => "10",
    'height' => "20",
    'depth' => "12",
    'typeCode' => "ENV")
);

$url = "https://api_link";//Api Link
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
echo $result;

But it didn't show any result and no error

Chase
  • 9,289
  • 5
  • 51
  • 77

2 Answers2

1

Because you didn't initialize your cURL resource. Where is your curl_init() ?

$ch = curl_init();       // without this, there is no cURL to execute

Also fix the syntax error I mentioned in a comment above. Also check for errors

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • when I used the above code it showing "Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" – user3931851 Sep 03 '14 at 03:50
  • 1
    Then you also need to disable SSL verification option for your cURL call. You can issue another `setopt` call for that. See here http://stackoverflow.com/questions/6400300/https-and-ssl3-get-server-certificatecertificate-verify-failed-ca-is-ok – Hanky Panky Sep 03 '14 at 03:52
0
if( !function_exists('curl_version') )
    die("Curl function is disabled");

Check if curl_function is enabled or not

Parfait
  • 1,752
  • 1
  • 11
  • 12