2014-09-03 118 views
0

我有麻烦了。从HunterExpress API retieve价值观,我想为通过邮政编码,产品尺寸/重量等我使用下面的代码来获取运费我们怎样才能从API

取运费金额
$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; 

但它并没有显示出任何结果,并没有错误

+0

结果变量是空的还是什么? – 2014-09-03 03:39:30

+0

结果变量为空 – user3931851 2014-09-03 03:41:10

+0

它可能是API,它可能只是因为身份验证方法错误而丢失请求,请查看返回头文件。 – cujo 2014-09-03 03:41:14

回答

0
if(!function_exists('curl_version')) 
    die("Curl function is disabled"); 

或者检查是否启用curl_function不

+0

我用上面的代码检查了curl函数是否启用 – user3931851 2014-09-03 03:43:03

+0

是$ ch = curl_init() ;定义了? – Parfait 2014-09-03 03:46:54

1

因为你没有初始化卷曲资源。你的curl_init()在哪里?

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

还修复了我在上面评论中提到的语法错误。还要检查错误

if(curl_exec($ch) === false) 
{ 
    echo 'Curl error: ' . curl_error($ch); 
} 
+0

当我使用上面的代码时它显示“Curl错误:SSL证书问题,请验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败“ – user3931851 2014-09-03 03:50:31

+1

然后,您还需要为您的cURL调用禁用SSL验证选项,您可以为此发出另一个'setopt'调用。 /问题/ 6400300/HTTPS-和SSL3-GET-服务器certificatecertificate-验证失败的-CA-是-OK – 2014-09-03 03:52:20