你可以把之前 json_encode($data);改爲http_build_query($data);
至於原因,請去看詳解:https://segmentfault.com/a/1190000006220620
如果還不可以的話,你可以這樣
$url = "";
$ch = curl_init();
$post_data = array('a'=> $a, 'b'=> $b,'c' => $c, 'Time'=> time() );
$data_string = json_encode($post_data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post數據
curl_setopt($ch, CURLOPT_POST, 1);
// post的變量
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$output = curl_exec($ch);
curl_close($ch);
//打印獲得的數據
return json_decode($output);
}