Trello Api:Php Curl错误,来自服务器的空回复


Trello Api: Php Curl error empty reply from server

当我的网络应用程序中发生某些事件时,我想使用Trello Api创建一张新卡。我想使用Curl来完成请求。这是我的代码:

$url = "https://api.trello.com/1/cards?key=".$key."&token=".$token."&name=".$name."&idList=".$idList;
# init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);
# dont care about ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
# download and close
$output = curl_exec($ch);
$request =  curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);

我试着用fiddler使用相同的url,结果成功了。然而,使用此代码,我会返回错误"来自服务器的空回复"。有人知道我做错了什么吗?

不要将参数放在URL中,而是尝试将它们放在CURLOPT_POSTFIELDS中。

这对我有效:

$url = "https://api.trello.com/1/cards";
$fields = "key=$key&token=$token&name=$name&idList=$idList";
# init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // make sure we see the sended header afterwards
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);
# dont care about ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
# download and close
$output = curl_exec($ch);
$request =  curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);