1

Web アプリケーションで特定のイベントが発生したときに、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);

私はフィドラーで同じURLを使用しようとしましたが、うまくいきました。ただし、このコードでは、「サーバーからの返信がありません」というエラーが返されます。私が間違っていることを誰かが考えていますか?

4

1 に答える 1

2

引数を 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);
于 2012-09-04T22:38:48.963 に答える