【问题标题】:Trello Api: Php Curl error empty reply from serverTrello Api:来自服务器的 Php Curl 错误空回复
【发布时间】:2012-08-21 18:52:34
【问题描述】:

当我的网络应用程序中发生某些事件时,我想使用 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,并且成功了。但是,使用此代码,我会收到错误“来自服务器的空回复”。 有人知道我做错了什么吗?

【问题讨论】:

    标签: php api curl trello


    【解决方案1】:

    不要将参数放在 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-10
      • 2015-12-20
      • 2017-08-27
      • 1970-01-01
      • 2015-11-05
      • 2015-05-05
      • 2010-12-27
      • 1970-01-01
      相关资源
      最近更新 更多