我试图调用API并发布一些数据。我收到了以下回复:
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 docs
中的JSON示例$ curl -X POST EXTERNAL/URL/GOES/HERE -u $API_KEY: \
--form email=user1@domain1.com \
--form create_time='2012-05-03 09:45:23' \
--form search='Legal Assistant' \
--form location='Houston, TX' \
--form content-type=application/json
答案 0 :(得分:-1)
你忘了打电话了
curl_exec($ CH);
后
$ response = curl_exec($ ch);
// execute!
$response = curl_exec($ch);
curl_exec($ch);
// close the connection, release resources
curl_close($ch);