我想調用一個API並POST一些數據。我得到如下回應:php curl返回空字符串
string '' (length=0).
這裏是代碼:
$subscriberInfo = [
$subscriberEmail => $email,
$subscriberJobType => $jobType,
$subscriberLocation => $location
];
$ch = curl_init('https://URLTOEXTERNALSITE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: MY API KEY HERE', 'Content-Type: text/x-php-serialization'
));
// execute!
$response = curl_exec($ch);
// close the connection, release resources
curl_close($ch);
var_dump($response);
die();
爲什麼我只得到返回一個空字符串?
編輯
這是一個從API文檔
$ curl -X POST EXTERNAL/URL/GOES/HERE -u $API_KEY: \
--form [email protected] \
--form create_time='2012-05-03 09:45:23' \
--form search='Legal Assistant' \
--form location='Houston, TX' \
--form content-type=application/json
http://php.net/manual/en/function.curl-error.php – Deep
Shoudnt你有POSTFILEDS $ subscriberInfo而不是$張貼? – Mihai
@Deep - 沒有記錄錯誤 –